Authentication
Picket Web Service uses a standard based OAuth 2.0 Client Credentials grant authentication method. You can use any library that provides support for this flow.
In this flow client service exchanges Client ID and Client Secret (API keys management) for an access token using the authentication token endpoint. This endpoint allows to obtain access token as well as the refresh token.
Example code
In this example code we are using simple-oauth2 library to get the access token.
import { ClientCredentials } from 'simple-oauth2';
const oauthConfig = {
client: {
id: 'insert your Client ID',
secret: 'insert your Client Secret',
},
auth: {
tokenHost: 'https://api.pickethomes.com/',
tokenPath: '/v1/auth/token',
refreshPath: '/v1/auth/token'
},
http: {
json: true,
},
options: {
bodyFormat: 'json',
authorizationMethod: 'body'
}
}
const clientCredentials = new ClientCredentials(oauthConfig);
try {
let accessToken = await clientCredentials.getToken({});
console.log(accessToken); // client_credentials flow
// one can refresh the token with call
// accessToken = await accessToken.refresh({});
// console.log(accessToken); // refresh_token flow
} catch (error) {
console.log('Access Token Error', error.message);
}