Help Center/ Identity and Access Management/ FAQs/ Others/ How Do I Obtain a User Token Using Postman?
Updated on 2024-04-25 GMT+08:00

How Do I Obtain a User Token Using Postman?

Postman is a visual editing tool for building and testing API requests. It provides an easy-to-use user interface to send HTTP requests, including GET, PUT, POST, and DELETE requests. Postman allows you to modify parameters of HTTP requests and returns response to your requests.

A token is a user's access credential, which includes user identities and permissions. When you call an API to access cloud resources, a token is required for identity authentication.

Perform the procedure described in this section to obtain a user token using Postman. For details about the parameters, see Obtaining a User Token.

  • Validity period of a token

    The validity period of a token is 24 hours. Cache your token to prevent frequent API calling. Ensure that the token is valid while you use it. Using a token that will soon expire may cause API calling failures.

    Obtaining a new token does not affect the validity of the existing token. However, the following operations will invalidate the existing token:

    • Deleting or disabling the IAM user
    • Changing the IAM user's password or access key
    • The IAM user's permissions are changed (due to outstanding payments, OBT application approval, or permission modification).
  • Obtaining a token
    • If your Huawei Cloud account has been upgraded to a HUAWEI ID, you cannot obtain a token using the HUAWEI ID. However, you can create an IAM user, grant the user required permissions, and obtain a token as the user.
    • If you are a user of a third-party system, you cannot obtain a token by using the username and password that you use for federated identity authentication. Go to the Huawei Cloud login page, click Forgot password, click Reset Huawei Cloud account password, and set a password.

Prerequisites

You have installed and registered with Postman.

  • You are advised to install a Postman version that supports a header larger than 32 KB. Otherwise, a header overflow error may be reported.

Procedure

  1. Edit the request URL, header, and body of the API used to obtain a token for calling APIs.

    • Request URL
      The request URL is in the format "https://IAM region and endpoint/API URI".
      1. Obtain the IAM region and endpoint.

          

      2. Obtain the API URI from Obtaining a User Token.

        For example, the request URL in the eu-west-101 region is https://iam.myhuaweicloud.eu/v3/auth/tokens.

      3. Select an API request method and enter the request URL in Postman.

          

    • Request Header

      Set key to Content-Type and value to application/json;charset=utf8.

        

    • Request Body
      Modify parameters in the example request body.
      {
      	"auth": {
      		"identity": {
      			"methods": [
                                      "password"
                               ],
      			"password": {
      				"user": {
      					"domain": {
      						"name": "Account name"
      					},
      					"name": "IAM user name",
      					"password": "IAM user password"
      				}
      			}
      		},
      		"scope": {
      			"domain": {
      				"name": "Account name"
      			}
      		}
      	}
        }

      For details about how to obtain the account name and IAM user name, see Obtaining Account, IAM User, and Project Information.

  2. Click Send to send the API request.

      

  3. View the token in the response header. You can use this token for authentication when you call other IAM APIs.

Why Am I Seeing a Message Indicating Header Overflow When I Attempt to Use Postman to Obtain a Token?

Postman of V7.25.0, V7.26.0, or a later version cannot be used to obtain a user token due to configurations. The message "Header Overflow" will be displayed if you use any of these versions.

  • Solution 1

    Use an earlier version of Postman, such as V 5.xx.

  • Solution 2:

    Use curl to obtain a token and replace the text in bold with actual values:

    curl -ik -X POST -H 'Content-Type=application/json;charset=utf8' -d '{"auth": {"identity": {"methods": ["password"],"password": {"user": {"domain": {"name": "Account name"},"name": "IAM username","password": "IAM user password"}}},"scope": {"domain": {"name": "Account name"}}}}' https://iam.myhuaweicloud.eu/v3/auth/tokens
  • Solution 3

    Pass an additional environment variable NODE_OPTIONS=--max-http-header-size=16384 (16 KB) to Postman to specify the maximum size of the HTTP header (in bytes).

    Run one of the following commands depending on your OS:

    • macOS
      NODE_OPTIONS=--max-http-header-size=16384 /Applications/Postman.app/Contents/MacOS/Postman 
    • Linux
      NODE_OPTIONS=--max-http-header-size=16384 /path/to/Postman/Postman 
    • Windows
      set NODE_OPTIONS=--max-http-header-size=16384 
      C:\users\<username>\AppData\local\Postman\Postman.exe