review fixes

This commit is contained in:
Raghunandan
2020-06-04 15:12:50 +02:00
parent 499c784c97
commit bacb2cf3a8
4 changed files with 34 additions and 17 deletions
@@ -24,6 +24,7 @@ import {
AccessTokenOptions,
ProfileInfoApi,
ProfileInfoOptions,
ProfileInfo,
} from '../../../definitions/auth';
import { OAuthRequestApi, AuthProvider } from '../../../definitions';
import { SessionManager } from '../../../../lib/AuthSessionManager/types';
@@ -41,7 +42,7 @@ type CreateOptions = {
};
export type GoogleAuthResponse = {
profile: any;
profile: ProfileInfo;
accessToken: string;
idToken: string;
scope: string;
@@ -135,21 +135,31 @@ export const executeRefreshTokenStrategy = async (
);
}
anyStrategy.userProfile(
resolve({
accessToken,
(error: Error, passportProfile: passport.Profile) => {
if (error) {
reject(error);
}
const profile = makeProfileInfo(passportProfile, params);
resolve({
accessToken,
params,
profile,
});
},
);
params,
});
},
);
});
};
export const executeFetchUserProfileStrategy = async (
providerstrategy: passport.Strategy,
accessToken: string,
params: any,
): Promise<ProfileInfo> => {
return new Promise((resolve, reject) => {
const anyStrategy = providerstrategy as any;
anyStrategy.userProfile(
accessToken,
(error: Error, passportProfile: passport.Profile) => {
if (error) {
reject(error);
}
const profile = makeProfileInfo(passportProfile, params);
resolve(profile);
},
);
});
@@ -21,6 +21,7 @@ import {
executeRedirectStrategy,
executeRefreshTokenStrategy,
makeProfileInfo,
executeFetchUserProfileStrategy,
} from '../PassportStrategyHelper';
import {
OAuthProviderHandlers,
@@ -81,12 +82,18 @@ export class GoogleAuthProvider implements OAuthProviderHandlers {
refreshToken: string,
scope: string,
): Promise<AuthInfoWithProfile> {
const { accessToken, params, profile } = await executeRefreshTokenStrategy(
const { accessToken, params } = await executeRefreshTokenStrategy(
this._strategy,
refreshToken,
scope,
);
const profile = await executeFetchUserProfileStrategy(
this._strategy,
accessToken,
params,
);
return {
accessToken,
idToken: params.id_token,
@@ -87,5 +87,4 @@ export type ProfileInfo = {
export type RefreshTokenResponse = {
accessToken: string;
params: any;
profile: ProfileInfo;
};