Skip to content

Commit

Permalink
feat(auth): adjusted the profile
Browse files Browse the repository at this point in the history
  • Loading branch information
stephane-segning committed Nov 28, 2023
1 parent 2cd306c commit 5f4ae88
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 25 deletions.
16 changes: 7 additions & 9 deletions packages/medusa-plugin-auth/src/auth-strategies/steam/admin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Strategy as SteamStrategy} from 'passport-steam';
import { Strategy as SteamStrategy } from 'passport-steam';
import { ConfigModule, MedusaContainer } from '@medusajs/medusa/dist/types/global';
import { Router } from 'express';
import { STEAM_ADMIN_STRATEGY_NAME, SteamAuthOptions, Profile } from './types';
import { Profile, STEAM_ADMIN_STRATEGY_NAME, SteamAuthOptions } from './types';
import { PassportStrategy } from '../../core/passport/Strategy';
import { validateAdminCallback } from '../../core/validate-callback';
import { passportAuthRoutesBuilder } from '../../core/passport/utils/auth-routes-builder';
Expand All @@ -13,7 +13,7 @@ export class SteamAdminStrategy extends PassportStrategy(SteamStrategy, STEAM_AD
protected readonly container: MedusaContainer,
protected readonly configModule: ConfigModule,
protected readonly strategyOptions: SteamAuthOptions,
protected readonly strict?: AuthOptions['strict']
protected readonly strict?: AuthOptions['strict'],
) {
super({
returnURL: strategyOptions.admin.callbackUrl,
Expand All @@ -25,18 +25,16 @@ export class SteamAdminStrategy extends PassportStrategy(SteamStrategy, STEAM_AD

async validate(
req: Request,
accessToken: string,
refreshToken: string,
profile: Profile
identifier: string,
profile: Profile,
): Promise<null | { id: string }> {
if (this.strategyOptions.admin.verifyCallback) {
return await this.strategyOptions.admin.verifyCallback(
this.container,
req,
accessToken,
refreshToken,
identifier,
profile,
this.strict
this.strict,
);
}

Expand Down
16 changes: 7 additions & 9 deletions packages/medusa-plugin-auth/src/auth-strategies/steam/store.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Router } from 'express';
import { ConfigModule, MedusaContainer } from '@medusajs/medusa/dist/types/global';
import {Strategy as SteamStrategy} from 'passport-steam';
import { Strategy as SteamStrategy } from 'passport-steam';
import { PassportStrategy } from '../../core/passport/Strategy';
import { STEAM_STORE_STRATEGY_NAME, SteamAuthOptions, Profile } from './types';
import { Profile, STEAM_STORE_STRATEGY_NAME, SteamAuthOptions } from './types';
import { passportAuthRoutesBuilder } from '../../core/passport/utils/auth-routes-builder';
import { validateStoreCallback } from '../../core/validate-callback';
import { AuthOptions } from '../../types';
Expand All @@ -12,7 +12,7 @@ export class SteamStoreStrategy extends PassportStrategy(SteamStrategy, STEAM_ST
protected readonly container: MedusaContainer,
protected readonly configModule: ConfigModule,
protected readonly strategyOptions: SteamAuthOptions,
protected readonly strict?: AuthOptions['strict']
protected readonly strict?: AuthOptions['strict'],
) {
super({
returnURL: strategyOptions.store.callbackUrl,
Expand All @@ -24,18 +24,16 @@ export class SteamStoreStrategy extends PassportStrategy(SteamStrategy, STEAM_ST

async validate(
req: Request,
accessToken: string,
refreshToken: string,
profile: Profile
identifier: string,
profile: Profile,
): Promise<null | { id: string }> {
if (this.strategyOptions.store.verifyCallback) {
return await this.strategyOptions.store.verifyCallback(
this.container,
req,
accessToken,
refreshToken,
identifier,
profile,
this.strict
this.strict,
);
}

Expand Down
29 changes: 22 additions & 7 deletions packages/medusa-plugin-auth/src/auth-strategies/steam/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,24 @@ import { AuthOptions } from '../../types';
export const STEAM_STORE_STRATEGY_NAME = 'steam.store.medusa-auth-plugin';
export const STEAM_ADMIN_STRATEGY_NAME = 'steam.admin.medusa-auth-plugin';

export type Profile = { emails: { value: string }[]; name?: { givenName?: string; familyName?: string } };
/**
* The profile returned from the steam strategy
*
* @see https://github.com/liamcurry/passport-steam/blob/master/lib/passport-steam/strategy.js#L30
*
* @param provider - The provider name
* @param id - The steam id
* @param _json - The raw json returned from steam
* @param displayName - The display name of the user
* @param photos - The photos of the user
*/
export type Profile = {
provider: 'steam';
id: string;
_json: any,
displayName?: string;
photos?: { value: string }[];
};

export type SteamAuthOptions = {
realm: string;
Expand All @@ -27,10 +44,9 @@ export type SteamAuthOptions = {
verifyCallback?: (
container: MedusaContainer,
req: Request,
accessToken: string,
refreshToken: string,
identifier: string,
profile: Profile,
strict?: AuthOptions['strict']
strict?: AuthOptions['strict'],
) => Promise<null | { id: string } | never>;

expiresIn?: number;
Expand All @@ -53,10 +69,9 @@ export type SteamAuthOptions = {
verifyCallback?: (
container: MedusaContainer,
req: Request,
accessToken: string,
refreshToken: string,
identifier: string,
profile: Profile,
strict?: AuthOptions['strict']
strict?: AuthOptions['strict'],
) => Promise<null | { id: string } | never>;

expiresIn?: number;
Expand Down

0 comments on commit 5f4ae88

Please sign in to comment.