Skip to content
This repository was archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
feat(authentication): allow dotted accessTokenProp
Browse files Browse the repository at this point in the history
  • Loading branch information
doktordirk committed May 27, 2016
1 parent 877fa50 commit 27198f8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export class Authentication {
getTokenFromResponse(response, tokenProp, tokenName, tokenRoot) {
if (!response) return undefined;

const responseTokenProp = response[tokenProp];
const responseTokenProp = tokenProp.split('.').reduce((o, x) => o[x], response);

if (typeof responseTokenProp === 'string') {
return responseTokenProp;
Expand Down
4 changes: 2 additions & 2 deletions src/baseConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class BaseConfig {
authHeader = 'Authorization';
// The token name used in the header of API requests that require authentication
authTokenType = 'Bearer';
// The the property from which to get the access token after a successful login or signup
// The the property from which to get the access token after a successful login or signup. Can also be dotted eg "accessTokenProp.accessTokenName"
accessTokenProp = 'access_token';


Expand All @@ -104,7 +104,7 @@ export class BaseConfig {
autoUpdateToken = true;
// Oauth Client Id
clientId = false;
// The the property from which to get the refresh token after a successful token refresh
// The the property from which to get the refresh token after a successful token refresh. Can also be dotted eg "refreshTokenProp.refreshTokenProp"
refreshTokenProp = 'refresh_token';

// If the property defined by `refreshTokenProp` is an object:
Expand Down
7 changes: 7 additions & 0 deletions test/authentication.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,13 @@ describe('Authentication', () => {
)).toBe('some');
});

it('Should return token if response has a string in dotted tokenProp', () => {
expect(authentication.getTokenFromResponse(
{tokenProp: {tokenName: 'some'}},
'tokenProp.tokenName'
)).toBe('some');
});

it('Should return token if response has a string in tokenName of tokenProp', () => {
expect(authentication.getTokenFromResponse(
{tokenProp: {tokenName: 'some'}},
Expand Down

0 comments on commit 27198f8

Please sign in to comment.