Revamp auth module to support multiple providers linked to a single auth identity (#7521)

This commit is contained in:
Stevche Radevski
2024-06-05 07:47:16 +00:00
committed by GitHub
parent 20cd6a7b51
commit fafc92b875
23 changed files with 640 additions and 216 deletions
@@ -12,30 +12,14 @@ export type AuthIdentityDTO = {
id: string
/**
* The ID of the provider used to authenticate the user.
*/
provider: string
/**
* The user's identifier. For example, when using the `emailpass`
* provider, the `entity_id` would be the user's email.
*/
entity_id: string
* The list of provider identities linked to the auth identity.
**/
provider_identities?: ProviderIdentityDTO[]
/**
* Holds information related to the actor IDs tied to the auth identity.
*/
app_metadata?: Record<string, unknown>
/**
* Holds custom data related to the provider in key-value pairs.
*/
provider_metadata?: Record<string, unknown>
/**
* Holds custom data related to the user in key-value pairs.
*/
user_metadata: Record<string, unknown>
}
/**
@@ -50,31 +34,14 @@ export type CreateAuthIdentityDTO = {
id?: string
/**
* The ID of the provider used to authenticate
* the user.
*/
provider: string
/**
* The user's identifier. For example, when using the `emailpass`
* provider, the `entity_id` would be the user's email.
*/
entity_id: string
* The list of provider identities linked to the auth identity.
**/
provider_identities?: CreateProviderIdentityDTO[]
/**
* Holds information related to the actor IDs tied to the auth identity.
*/
app_metadata?: Record<string, unknown>
/**
* Holds custom data related to the provider in key-value pairs.
*/
provider_metadata?: Record<string, unknown>
/**
* Holds custom data related to the user in key-value pairs.
*/
user_metadata?: Record<string, unknown>
}
/**
@@ -92,6 +59,101 @@ export type UpdateAuthIdentityDTO = {
* Holds information related to the actor IDs tied to the auth identity.
*/
app_metadata?: Record<string, unknown>
}
/**
* @interface
*
* The provider identity details.
*/
export type ProviderIdentityDTO = {
/**
* The ID of the provider identity.
*/
id: string
/*
* The ID of the provider used to authenticate the user.
*/
provider: string
/**
* The user's identifier. For example, when using the `emailpass`
* provider, the `entity_id` would be the user's email.
*/
entity_id: string
/**
* The auth identity linked to the provider identity.
*/
auth_identity?: AuthIdentityDTO
/**
* Holds custom data related to the provider in key-value pairs.
*/
provider_metadata?: Record<string, unknown>
/**
* Holds custom data related to the user in key-value pairs.
*/
user_metadata?: Record<string, unknown>
}
/**
* @interface
*
* The provider identity to be created.
*/
export type CreateProviderIdentityDTO = {
/**
* The ID of the provider identity.
*/
id?: string
/*
* The ID of the provider used to authenticate the user.
*/
provider: string
/**
* The user's identifier. For example, when using the `emailpass`
* provider, the `entity_id` would be the user's email.
*/
entity_id: string
/**
* The auth identity linked to the provider identity. Needs to be specified if creating a new provider identity directly.
*/
auth_identity_id?: string
/**
* Holds custom data related to the provider in key-value pairs.
*/
provider_metadata?: Record<string, unknown>
/**
* Holds custom data related to the user in key-value pairs.
*/
user_metadata?: Record<string, unknown>
}
/**
* @interface
*
* The provider identity to be created.
*/
export type UpdateProviderIdentityDTO = {
/**
* The ID of the provider identity.
*/
id: string
/**
* The user's identifier. For example, when using the `emailpass`
* provider, the `entity_id` would be the user's email.
*/
entity_id: string
/**
* Holds custom data related to the provider in key-value pairs.
*/
@@ -114,7 +176,17 @@ export interface FilterableAuthIdentityProps
id?: string[]
/**
* Filter the auth identities by the ID of their auth provider.
* The provider identities to filter the auth identity by.
*/
provider?: string[] | string
provider_identities?: {
/**
* Filter the provider identities by the ID of the provider identity ID they are linked to.
*/
entity_id?: string
/**
* Filter the provider identities by the provider handle.
*/
provider?: string
}
}
@@ -1,3 +1,5 @@
import { AuthIdentityDTO } from "./auth-identity"
/**
* @interface
*
@@ -12,7 +14,7 @@ export type AuthenticationResponse = {
/**
* The authenticated user's details.
*/
authIdentity?: any
authIdentity?: AuthIdentityDTO
/**
* If an error occurs during the authentication process,
+5 -4
View File
@@ -2,16 +2,17 @@ import {
AuthIdentityDTO,
AuthenticationInput,
AuthenticationResponse,
CreateAuthIdentityDTO,
} from "./common"
// This interface currently won't allow for linking multiple providers to a single auth entity. That flow is more complex and not supported yet.
export interface AuthIdentityProviderService {
// The provider is injected by the auth identity module
retrieve: (selector: {
retrieve: (selector: { entity_id: string }) => Promise<AuthIdentityDTO>
create: (data: {
entity_id: string
provider: string
provider_metadata?: Record<string, unknown>
user_metadata?: Record<string, unknown>
}) => Promise<AuthIdentityDTO>
create: (data: CreateAuthIdentityDTO) => Promise<AuthIdentityDTO>
}
/**
+12 -13
View File
@@ -10,13 +10,6 @@ import { Context } from "../shared-context"
import { FindConfig } from "../common"
import { IModuleService } from "../modules-sdk"
/**
* @ignore
*/
export type JWTGenerationOptions = {
expiresIn?: string | number
}
/**
* The main service interface for the Auth Module.
*/
@@ -196,12 +189,16 @@ export interface IAuthModuleService extends IModuleService {
* @example
* const authIdentities = await authModuleService.create([
* {
* provider: "emailpass",
* entity_id: "user@example.com",
* provider_identities: [{
* provider: "emailpass",
* entity_id: "user@example.com",
* }]
* },
* {
* provider: "google",
* entity_id: "user@gmail.com",
* provider_identities: [{
* provider: "google",
* entity_id: "user@gmail.com",
* }]
* },
* ])
*/
@@ -219,8 +216,10 @@ export interface IAuthModuleService extends IModuleService {
*
* @example
* const authIdentity = await authModuleService.create({
* provider: "emailpass",
* entity_id: "user@example.com",
* provider_identities: [{
* provider: "emailpass",
* entity_id: "user@example.com",
* }]
* })
*/
create(