Skip to content

Commit

Permalink
fix(authentication-oauth): Add getEntity method to oAuth authenticati…
Browse files Browse the repository at this point in the history
…on and remove provider field for other calls (#1935)
  • Loading branch information
daffl committed Apr 29, 2020
1 parent e8464f3 commit d925c1b
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions packages/authentication-oauth/src/strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
AuthenticationRequest, AuthenticationBaseStrategy, AuthenticationResult
} from '@feathersjs/authentication';
import { Params } from '@feathersjs/feathers';
import { NotAuthenticated } from '@feathersjs/errors';

const debug = Debug('@feathersjs/authentication-oauth/strategy');

Expand Down Expand Up @@ -126,8 +127,27 @@ export class OAuthStrategy extends AuthenticationBaseStrategy {
return this.entityService.patch(id, data, params);
}

async authenticate (authentication: AuthenticationRequest, params: Params) {
async getEntity (result: any, params: Params) {
const { entityService } = this;
const { entityId = entityService.id, entity } = this.configuration;

if (!entityId || result[entityId] === undefined) {
throw new NotAuthenticated('Could not get oAuth entity');
}

if (!params.provider) {
return result;
}

return entityService.get(result[entityId], {
...params,
[entity]: result
});
}

async authenticate (authentication: AuthenticationRequest, originalParams: Params) {
const entity: string = this.configuration.entity;
const { provider, ...params } = originalParams;
const profile = await this.getProfile(authentication, params);
const existingEntity = await this.findEntity(profile, params)
|| await this.getCurrentEntity(params);
Expand All @@ -139,7 +159,7 @@ export class OAuthStrategy extends AuthenticationBaseStrategy {

return {
authentication: { strategy: this.name },
[entity]: authEntity
[entity]: await this.getEntity(authEntity, originalParams)
};
}
}

0 comments on commit d925c1b

Please sign in to comment.