Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change token auth provider usage of created to invaliated_tokens #27614

Merged
merged 3 commits into from
Jan 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ describe('TokenAuthenticationProvider', () => {

callWithInternalUser
.withArgs('shield.deleteAccessToken', { body: { token: accessToken } })
.returns({ created: true });
.returns({ invalidated_tokens: 1 });

const failureReason = new Error('failed to delete token');
callWithInternalUser
Expand All @@ -451,11 +451,11 @@ describe('TokenAuthenticationProvider', () => {

callWithInternalUser
.withArgs('shield.deleteAccessToken', { body: { token: accessToken } })
.returns({ created: true });
.returns({ invalidated_tokens: 1 });

callWithInternalUser
.withArgs('shield.deleteAccessToken', { body: { refresh_token: refreshToken } })
.returns({ created: true });
.returns({ invalidated_tokens: 1 });

const authenticationResult = await provider.deauthenticate(request, { accessToken, refreshToken });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,27 +119,35 @@ export class TokenAuthenticationProvider {

try {
// First invalidate the access token.
const { created: deletedAccessToken } = await this._options.client.callWithInternalUser(
const { invalidated_tokens: invalidatedAccessTokensCount } = await this._options.client.callWithInternalUser(
'shield.deleteAccessToken',
{ body: { token: state.accessToken } }
);

if (deletedAccessToken) {
if (invalidatedAccessTokensCount === 0) {
this._options.log(['debug', 'security', 'token'], 'User access token was already invalidated.');
} else if (invalidatedAccessTokensCount === 1) {
this._options.log(['debug', 'security', 'token'], 'User access token has been successfully invalidated.');
} else {
this._options.log(['debug', 'security', 'token'], 'User access token was already invalidated.');
this._options.log(['debug', 'security', 'token'],
`${invalidatedAccessTokensCount} user access tokens were invalidated, this is unexpected.`
);
}

// Then invalidate the refresh token.
const { created: deletedRefreshToken } = await this._options.client.callWithInternalUser(
const { invalidated_tokens: invalidatedRefreshTokensCount } = await this._options.client.callWithInternalUser(
'shield.deleteAccessToken',
{ body: { refresh_token: state.refreshToken } }
);

if (deletedRefreshToken) {
if (invalidatedRefreshTokensCount === 0) {
this._options.log(['debug', 'security', 'token'], 'User refresh token was already invalidated.');
} else if (invalidatedRefreshTokensCount === 1) {
this._options.log(['debug', 'security', 'token'], 'User refresh token has been successfully invalidated.');
} else {
this._options.log(['debug', 'security', 'token'], 'User refresh token was already invalidated.');
this._options.log(['debug', 'security', 'token'],
`${invalidatedRefreshTokensCount} user refresh tokens were invalidated, this is unexpected.`
);
}

return DeauthenticationResult.redirectTo(
Expand Down