Skip to main content

Authentication API

exchangeCodeForAccessToken

This function lets you exchange your access code for access and refresh tokens. If you do not have an access code, see the guide on authenticating manually.

Example

import { exchangeCodeForAccessToken } from "psn-api";

const authorization = await exchangeCodeForAccessToken(accessCode);

Parameters

NameTypeDescription
accessCodestringYour access code.

Returns

An AccessTokenResponse object, containing the following properties:

NameTypeDescription
accessTokenstringUsed to retrieve data from the PSN API.
expiresInnumberWhen the access token will expire.
idTokenstring
refreshTokenstringUsed to retrieve a new access token after it expires.
refreshTokenExpiresInnumberWhen the refresh token will expire.
scopestring
tokenTypestring

Source

authenticate/exchangeCodeForAccessToken.ts


exchangeNpssoForCode

This function lets you exchange your NPSSO token for an access code. If you do not have an NPSSO, see the guide on authenticating manually.

Example

import { exchangeNpssoForCode } from "psn-api";

const accessCode = await exchangeNpssoForCode("<my 64-digit NPSSO>");

console.log(accessCode); // --> "v3.ABCDEF"

Parameters

NameTypeDescription
npssoTokenstringYour NPSSO token.

Returns

Promise<string>

An access code, which can be exchanged for access and refresh tokens with exchangeCodeForAccessToken().

Source

authenticate/exchangeNpssoForCode.ts