Configure your application
Before you can implement authorization, you need to register your app in OAuth2 by creating an app integration from Workfront.
For instructions on creating the OAuth2 application, see Create an OAuth2 single-page web application using PKCE in Create OAuth2 applications for Workfront integrations
Create the Proof Key for Code Exchange
Similar to the standard Authorization Code flow, your app starts by redirecting the user’s browser to your Authorization Server’s /authorize endpoint. However, in this instance you also have to pass along a code challenge.
Your first step is to generate a code verifier and challenge.
You must add code in your client app to create the code verifier and code challenge.
The PKCE generator code creates output similar to the following:
{
"code\_verifier":"N28zVMsKU6ptUjHaYWg3T1NFTDQqcW1R4BU5NXywapNac4hhfkxjwfhZQat",
"code\_challenge":"wzgjYF9qEiWep-CwqgrTE78-2ghjwCtRO3vj23o4W\_fw"
}
Your app saves the code_verifier for later, and sends the code_challenge along with the authorization request to your Authorization Server’s /authorize URL.
Request an authorization code
If you are using the default Custom Authorization Server, then your request URL would be similar to the following:
/authorize?client\_id=<clientID>&response\_type=code&redirect\_uri=<redirectURL>
&code\_challenge\_method=S256&code\_challenge=wzgjYF9qEiWep-CwqgrTE78-2ghjwCtRO3vj23o4W\_fw"
Note the parameters that are being passed:
-
client_idmatches the Client ID of the OAuth2 application that you created in the when configuring the application.For instructions, see Create an OAuth2 single-page web application using PKCE in Create OAuth2 applications for Workfront integrations.
-
response_typeiscode, because the application uses the Authorization Code grant type. -
redirect_uriis the callback location that the user agent is directed to along with thecode. This must match one of the redirect URls that you specified when you created your OAuth2 application. -
code_challenge_methodis the hash method used to generate the challenge, which is alwaysS256for Workfront Oauth2 applications that use PKCE. -
code_challengeis the code challenge used for PKCE.
Exchange the code for tokens
To exchange the authorization code for an access token, pass it to your Authorization Server’s /token endpoint along with the code_verifier.
/token \\
--header 'accept: application/json' \\
--header 'cache-control: no-cache' \\
--header 'content-type: application/x-www-form-urlencoded' \\
--data 'grant\_type=authorization\_code&client\_id=<clientID>&redirect\_uri=<redirectURL>&code=<code>&code\_verifier=N28zVMsKU6ptUjHaYWg3T1NFTDQqcW1R4BU5NXywapNac4hhfkxjwfhZQat
Note the parameters that are being passed:
-
grant_typeisauthorization_code, because the app uses the the Authorization Code grant type. -
redirect_urimust match the URI that was used to get the authorization code. -
codeis the authorization code that you received from the /authorize endpoint. -
code_verifieris the PKCE code verifier that your app generated in Create the Proof Key for Code Exchange. -
client_ididentifies your client and must match the value preregistered in OAuth2.
If the code is still valid, and the code verifier matches, your application receives an access token.
{
"access\_token": "eyJhd\[...\]Yozv",
"expires\_in": 3600,
"token\_type": "Bearer"
}