brandauther-nodejs-client
v0.0.4
Published
Brandauther nodejs api client
Downloads
3
Readme
Brandauther: node API client
Encoder configuration
const encoder = new Encoder({
publicKey: "RSA public key",
algorithm: "RS256",
issuerName: "issuer",
verifyIssuer: true,
dataEncryptionKey: "key to decode ids",
})
Token decryption
encoder.decode(jwtTokenString)
- decodes jwt token to semantic object representationencoder.safeDecode(jwtTokenString)
- decode token object and when something went wrong returnsnull
- subject id (player id) is encrypted on the brandauther side so the decrypted data variant will be represented as an object attribute on the token object instance (for example: playerExternalId)
- Returns
AccessToken | RefreshToken | GuestToken
or can be called with certain type if you know what kind of token it is:const decoded = encoder.decode<AccessToken>(jwtTokenString)
- For types description see interfaces/token.interface.d.ts
Token verification
- verify token signature only:
encoder.isTokenSignatureValid(jwtTokenString) // true/false
- validate token: verify token signature AND token object
structure/data consistency/semantic values/expiration/etc
(and when something went wrong - returns
false
)
encoder.isTokenValid(jwtTokenString) // true/false
// NOTE: with custom issuer_name (iss) comparison validation
// NOTE: for example: original iss 'kekpek', got 'kek':
encoder.isTokenValid(jwtTokenString, "kek", true) // false
encoder.isTokenValid(jwtTokenString, "kek", false) // true
Token parsing
You can parse JWT token from string representation (base64-dot-separated format) to an object
encoder.parse(jwtToken)
: parse JWT token to a jwt.Jwt object- parses jwtToken string into a jwt.Jwt object with
headerds
,payload
andsignature
properties, whereheaders
andpayload
stores corresponding header and payload token fields as a parsed JSON.signature
stores the non-touched token's signature part (string bytes in Base64-encoded format)
- parses jwtToken string into a jwt.Jwt object with
Nest.js integration
For Nest.js integration import and configure BrandautherModule:
@Module({
imports: [BrandautherModule.register(options)]
})
export class MyModule {}
options
are the same as Encoder options