ExternalAuthenticationService
ExternalAuthenticationService
This is a helper service which exposes methods related to looking up and creating Users based on an external AuthenticationStrategy.
Signature
class ExternalAuthenticationService {
constructor(connection: TransactionalConnection, roleService: RoleService, historyService: HistoryService, customerService: CustomerService, administratorService: AdministratorService, channelService: ChannelService)
async findCustomerUser(ctx: RequestContext, strategy: string, externalIdentifier: string, checkCurrentChannelOnly: = true) => Promise<User | undefined>;
async findAdministratorUser(ctx: RequestContext, strategy: string, externalIdentifier: string) => Promise<User | undefined>;
async createCustomerAndUser(ctx: RequestContext, config: {
strategy: string;
externalIdentifier: string;
verified: boolean;
emailAddress: string;
firstName?: string;
lastName?: string;
}) => Promise<User>;
async createAdministratorAndUser(ctx: RequestContext, config: {
strategy: string;
externalIdentifier: string;
identifier: string;
emailAddress?: string;
firstName?: string;
lastName?: string;
roles: Role[];
}) => ;
async findUser(ctx: RequestContext, strategy: string, externalIdentifier: string) => Promise<User | undefined>;
}
Members
constructor
method
type:
(connection: TransactionalConnection, roleService: RoleService, historyService: HistoryService, customerService: CustomerService, administratorService: AdministratorService, channelService: ChannelService) => ExternalAuthenticationService
findCustomerUser
method
type:
(ctx: RequestContext, strategy: string, externalIdentifier: string, checkCurrentChannelOnly: = true) => Promise<User | undefined>
Looks up a User based on their identifier from an external authentication provider, ensuring this User is associated with a Customer account.
By default, only customers in the currently-active Channel will be checked.
By passing false
as the checkCurrentChannelOnly
argument, all channels
will be checked.
findAdministratorUser
method
type:
(ctx: RequestContext, strategy: string, externalIdentifier: string) => Promise<User | undefined>
Looks up a User based on their identifier from an external authentication
provider, ensuring this User is associated with an Administrator account.
createCustomerAndUser
method
type:
(ctx: RequestContext, config: { strategy: string; externalIdentifier: string; verified: boolean; emailAddress: string; firstName?: string; lastName?: string; }) => Promise<User>
If a customer has been successfully authenticated by an external authentication provider, yet cannot
be found using
findCustomerUser
, then we need to create a new User and
Customer record in Vendure for that user. This method encapsulates that logic as well as additional
housekeeping such as adding a record to the Customer’s history.
createAdministratorAndUser
method
type:
(ctx: RequestContext, config: { strategy: string; externalIdentifier: string; identifier: string; emailAddress?: string; firstName?: string; lastName?: string; roles: Role[]; }) =>
If an administrator has been successfully authenticated by an external authentication provider, yet cannot
be found using
findAdministratorUser
, then we need to create a new User and
Administrator record in Vendure for that user.
findUser
method
type:
(ctx: RequestContext, strategy: string, externalIdentifier: string) => Promise<User | undefined>