feat(authentication, types, utils): Add Authentication provider scopes (#6228)
* initial implementation * add test for invalid scope * get config from scope not db * assign config from scope * fix package.json * optional providers * make providers options * update type
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import { AuthenticationResponse } from "@medusajs/types"
|
||||
import { AuthenticationResponse, AuthProviderScope } from "@medusajs/types"
|
||||
import { MedusaError } from "../common"
|
||||
|
||||
export abstract class AbstractAuthenticationModuleProvider {
|
||||
public static PROVIDER: string
|
||||
public static DISPLAY_NAME: string
|
||||
protected readonly scopes_: Record<string, AuthProviderScope>
|
||||
|
||||
public get provider() {
|
||||
return (this.constructor as Function & { PROVIDER: string }).PROVIDER
|
||||
@@ -13,6 +15,19 @@ export abstract class AbstractAuthenticationModuleProvider {
|
||||
.DISPLAY_NAME
|
||||
}
|
||||
|
||||
protected constructor({ scopes }) {
|
||||
this.scopes_ = scopes
|
||||
}
|
||||
|
||||
public validateScope(scope) {
|
||||
if (!this.scopes_[scope]) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.INVALID_ARGUMENT,
|
||||
`Scope "${scope}" is not valid for provider ${this.provider}`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
abstract authenticate(
|
||||
data: Record<string, unknown>
|
||||
): Promise<AuthenticationResponse>
|
||||
|
||||
Reference in New Issue
Block a user