You can use delegated access when you want to request and access other Paxful users accounts using API.
Delegated access mode relies on the OAuth 2.0 authorization code grant authentication flow. OAuth 2.0 is an industry standard, meaning you can use any of your favorite OAuth 2.0 libraries for authentication. A full list of Paxful OAuth 2.0 endpoints can be found at the end of this guide.
Paxful also provides SDKs for the most popular programming languages that you can use in your applications. For a list of available SDKs visit this page.
If you’re planning to use an SDK provided by Paxful or the OAuth 2.0 library provided by a third party, you’ll need to have an understanding of what happens behind the scenes to help troubleshoot authentication issues.
The authentication flow will look this:
Compared to direct access mode (which uses the OAuth 2.0 client credentials flow), the OAuth 2.0 authorization grant flow requires additional work before you can get a JWT. By relying on delegated access, your application will gain access to a Paxful customer account to the extent that the user has authorized it.
In order to receive a JWT while using delegated access, there are a few sub-steps:
curl --request POST \ --url 'https://accounts.paxful.com/oauth2/token' \ --header 'content-type: application/x-www-form-urlencoded' \ --data grant_type=authorization_code \ --data client_id=CLIENT_ID \ --data client_secret=CLIENT_SECRET \ --data code=CODE
Please note that in the authentication flow above, client_secret is never shared to a user in a browser - client_secret is used only to exchange code for an actual JWT and nowhere else. Never share client_secret with anyone, it must be kept in a safe place where only your application can access it.
Every API request you want to authenticate needs to include an “Authorization” header with the JWT as its value:
curl --request POST \ --url https://api.paxful.com/service/endpoint \ --header 'Authorization: Bearer ABC'
If a JWT has a scope granted that is represented in this case by service/endpoint API endpoint, your request will be authenticated and you will receive a proper response. If JWT is not authorized to invoke an endpoint, you will receive a 403 HTTP error.
Tokens that are received using Authorization Code Grant Flow have a lifetime of 1 hour. If you send an expired JWT, you will receive a 401 response code and need to get a fresh JWT using refresh_token that you have received in Step 5.
To get a new JWT using refresh_token, you need to send the following request:
curl --request POST \ --url 'https://accounts.paxful.com/oauth2/token' \ --header 'content-type: application/x-www-form-urlencoded' \ --data grant_type=refresh_token \ --data refresh_token=REFRESH_TOKEN \ --data client_id=CLIENT_ID \ --data client_secret=CLIENT_SECRET
Please note that when you are refreshing a token, grant_type is set to refresh_token. If successful and authorization has found a provided REFRESH_TOKEN, you will receive the same response as in step 5.
Once you have exchanged a refresh_token for a new access token, the given refresh_token gets decommissioned and next time the access token expires you need to use a fresh refresh token.
Once you create an application, you’ll need to add at least one API product to use it. If you already have an Application, you can visit the Products tab and add a product:
Every API product contains a set of API operations. When working with delegated access mode, before you can request access to an API operation, you need to have an API product that includes this operation added to your application. In OAuth 2.0 lingo, an API operation that is allowed to be invoked using a JWT that was received by exchanging client_id andclient_secret is called scope.
Contrary to direct access mode, when a JWT is issued through the authorization code grant flow, the JWT will only have access to scopes that a user has authorized. When working with delegated access mode, depending on the level of KYC that you as a developer have, you are able to request access to an additional set of API operations to perform on behalf of a user.
Endpoint type | URL |
---|---|
Authorization endpoint | https://accounts.paxful.com/oauth2/authorize |
Token endpoint | https://accounts.paxful.com/oauth2/token |
User info endpoint | https://accounts.paxful.com/oauth2/userinfo |
OpenID configuration endpoint | https://accounts.paxful.com/.well-known/openid-configuration |
API Gateway endpoint | https://api.paxful.com/ |