Password Grant Type
Password Grant Type for authenticating with Swift APIs
Tip
Swift provides sample code for different languages to help you get started with the Swift APIs.
The Password Grant Type is used to retrieve a token using the username and password. It is similar to the JWT Bearer Grant Type, but instead of using a JWT token, the username and password are used to authenticate. More detailed information about the Password Grant Type can be found in the OAuth 2.0 RFC.
Three parameters are required to retrieve a token:
| Parameter | Description |
|---|---|
| grant_type | The grant type. For the password grant type this is password |
| username | Use “License ID” for the API product in Live after subscribing. To try it out in Sandbox, use sandbox-id |
| password | Use “License Secret” for the API product in Live after subscribing. To try it out in Sandbox, use sandbox-key |
Please refer to the License ID & Secret section in the documentation for information on how to acquire these credentials in the Live environment.
Basic authorisation is required to request the token.
The credentials are the Consumer Key and Consumer Secret of the application created in the Application credentials guide guide.
POST /oauth2/v1/token HTTP/1.1
Host: sandbox.swift.com
Content-Type: application/x-www-form-urlencoded
Authorization: Basic MjJRU0JFQVFzQmR3dU5GNnNWalRqQWFZQ1JMT0tHMnZ0ajpramRzZmtkamZkMDk4OQ==
grant_type=password
&username=sandbox-id
&password=sandbox-keyThe access_token is used to authenticate the API calls and it is valid for 30 minutes.
After that, the token expires and a new token needs to be requested either using the refresh token
or by requesting a new token using the JWT Bearer Grant Type.