Reviewed-by: Belejkanic, Lukas <lukas.belejkanic@t-systems.com> Co-authored-by: weihongmin1 <weihongmin1@huawei.com> Co-committed-by: weihongmin1 <weihongmin1@huawei.com>
79 KiB
Obtaining a User Token Through Password Authentication and Virtual MFA
Function
This API is used to obtain an IAM user token using the username, password, and virtual MFA device. To use this API, ensure that virtual MFA-based login protection has been enabled for the IAM user. A token is an access credential issued to a user to bear its identity and permissions. The token obtained using this API can be used to authenticate API calls to IAM and other cloud services.
URI
POST /v3/auth/tokens
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
nocatalog |
No |
String |
If this parameter is set, no catalog information will be displayed in the response. Any non-empty string for this parameter will be interpreted as true and indicates that no catalog information will be displayed. |
Request
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
Content-Type |
Yes |
String |
Set this field to application/json;charset=utf8. |
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
Yes |
Object |
Authentication information. |
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
Yes |
Object |
Authentication parameters. |
|
Yes |
Object |
Application scope of the token. Value options: project and domain. NOTE:
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
methods |
Yes |
Array of strings |
Authentication method. The options are as follows:
|
Yes |
Object |
IAM user password authentication information. NOTE:
Authentication information. Example: "password": {
"user": {
"name": "user A",
"password": "**********",
"domain": {
"name": "domain A"
|
|
Yes |
Object |
Authentication information. This parameter is mandatory only if you have enabled virtual MFA-based login protection. You can specify either user.id or user.name. CAUTION:
Example 1: "totp": {
"user": {
"id": "b95b78b67fa045b38104c12fb...",
"passcode": "******"
Example 2: "totp": {
"user": {
"name": "user A",
"passcode": "******"
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
Yes |
Object |
Information about the IAM user who is requesting to obtain a token. |
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
Yes |
Object |
Information about the account used to create the IAM user. |
|
name |
Yes |
String |
IAM username. |
password |
Yes |
String |
Password of the IAM user. NOTE:
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
name |
Yes |
String |
Name of the account used to create the IAM user. |
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
Yes |
Object |
IAM user information. Login protection has been enabled for the IAM user, and a virtual MFA device is used for identity authentication. |
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
id |
Yes |
String |
ID of the IAM user for whom virtual MFA-based login protection has been enabled. |
passcode |
Yes |
String |
MFA verification code, which can be obtained on the MFA App. NOTE:
To obtain a token successfully, ensure that the verification code you provide is correct. |
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
No |
Object |
If this parameter is set to domain, the token can be used to access global services, such as OBS. Global services are not subject to any projects or regions. You can specify either id or name. domain.id is recommended. |
|
No |
Object |
If this parameter is set to project, the token can be used to access only services (such as ECS) in specific projects. You can specify either id or name. |
Example Request
- Sample request
The following is a sample request for obtaining a token for user A. The login password of the user is ********** and the domain name is domain A. The scope of the token is domain.
{ "auth": { "identity": { "methods": ["password"], "password": { "user": { "name": "user A", "password": "**********", "domain": { "name": "domain A" } } } }, "scope": { "domain": { "name": "domain A" } } } }The following is a sample request for obtaining a token when virtual MFA–based login authentication is enabled.
{ "auth": { "identity": { "methods": ["password", "totp"], "password": { "user": { "name": "user A", "password": "********", "domain": { "name": "domain A" } } }, "totp" : { "user": { "name": "user A", "passcode": "******" } } }, "scope": { "domain": { "name": "domain A" } } } }
Response
Parameter |
Type |
Description |
|---|---|---|
X-Subject-Token |
String |
Signed token. |
Parameter |
Type |
Description |
|---|---|---|
Object |
Token information. |
Parameter |
Type |
Description |
|---|---|---|
Array of objects |
Endpoint information. |
|
Object |
Account information about the IAM user who requests for the token. This parameter is returned only when the scope parameter in the request body has been set to domain. |
|
expires_at |
String |
Expiration date of the token. |
issued_at |
String |
Time when the token was issued. |
mfa_authn_at |
String |
MFA authentication time. This field is displayed only when virtual MFA–based login authentication is enabled. |
methods |
Array of strings |
Method for obtaining the token. |
Object |
Project information about the IAM user who requests for the token. This parameter is returned only when the scope parameter in the request body has been set to project. |
|
Array of objects |
Permissions information of the token. |
|
Object |
Information about the IAM user who requests for the token. |
Parameter |
Type |
Description |
|---|---|---|
Array of objects |
Endpoint information. |
|
id |
String |
Service ID. |
name |
String |
Service name. |
type |
String |
Type of the service to which the API belongs. |
Parameter |
Type |
Description |
|---|---|---|
id |
String |
Endpoint ID. |
interface |
String |
Visibility of the API. public indicates that the API is available for public access. |
region |
String |
Region to which the endpoint belongs. |
region_id |
String |
Region ID. |
url |
String |
Endpoint URL. |
Parameter |
Type |
Description |
|---|---|---|
Object |
Domain information of the project. |
|
id |
String |
Project ID. |
name |
String |
Project name. |
Parameter |
Type |
Description |
|---|---|---|
id |
String |
Domain ID. |
name |
String |
Domain name. |
Parameter |
Type |
Description |
|---|---|---|
name |
String |
Permission name. |
id |
String |
Permission ID. The default value is 0, which does not correspond to any permission. |
Example Response
- Example responseThe following is a sample request for obtaining a token for user A. The login password of the user is ********** and the domain name is domain A. The scope of the token is domain.
Token information stored in the response header: X-Subject-Token:MIIDkgYJKoZIhvcNAQcCoIIDgzCCA38CAQExDTALBglghkgBZQMEAgEwgXXXXX... Token information stored in the response body: { "token" : { "methods" : ["password"], "expires_at" : "2015-11-09T01:42:57.527363Z", "issued_at" : "2015-11-09T00:42:57.527404Z", "user" : { "domain" : { "id" : "ded485def148s4e7d2se41d5se...", "name" : "domain A" }, "id" : "ee4dfb6e5540447cb37419051...", "name" : "user A", "password_expires_at":"2016-11-06T15:32:17.000000", }, "domain" : { "name" : "domain A", "id" : "dod4ed5e8d4e8d2e8e8d5d2d..." }, "catalog": [{ "type": "identity", "id": "1331e5cff2a74d76b03da12259...", "name": "iam", "endpoints": [{ "url": "https://sample.domain.com/v3", "region": "*", "region_id": "*", "interface": "public", "id": "089d4a381d574308a703122d3a..." }] }], "roles" : [{ "name" : "role1", "id" : "roleid1" }, { "name" : "role2", "id" : "roleid2" } ] } }The following is a sample request for obtaining a token when virtual MFA–based login authentication is enabled.
Token information stored in the response header: X-Subject-Token:MIIDkgYJKoZIhvcNAQcCoIIDgzCCA38CAQExDTALBglghkgBZQMEAgEwgXXXXX... Token information stored in the response body: { "token": { "expires_at": "2020-09-05T06:50:44.390000Z", "mfa_authn_at": "2020-09-04T06:50:44.390000Z", "issued_at": "2020-09-04T06:50:44.390000Z", "methods": [ "password", "totp" ], "catalog": [ { "endpoints": [ { "id": "33e1cbdd86d34e89a63cf8ad16a5f...", "interface": "public", "region": "*", "region_id": "*", "url": "https://sample.domain.com/v3.0" } ], "id": "100a6a3477f1495286579b819d399...", "name": "iam", "type": "iam" }, ], "domain": { "id": "e6505630658e49649784759cdf251...", "name": "domain A" }, "roles": [ { "name" : "role1", "id" : "roleid1" },{ "name" : "role1", "id" : "roleid1" } ], "user": { "domain": { "id": "e6505630658e49649784759cdf251...", "name": "domain A" }, "id": "092ac6365a0025b11f76c01e90100...", "name": "user A", "password_expires_at": "" } } }
Status Codes
Status Code |
Description |
|---|---|
201 |
Creation succeeded. |
400 |
Invalid parameters. |
401 |
Authentication failed. |
403 |
Access denied. |
404 |
Requested resource cannot found. |
500 |
Internal server error. |
503 |
Service unavailable. |