Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PoC][WIP, not ready for review]feat: add abstractions in authentication module #2445

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
29 changes: 29 additions & 0 deletions packages/authentication/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// License text available at https://opensource.org/licenses/MIT

import {Request} from '@loopback/rest';
import {Entity} from '@loopback/repository';

/**
* interface definition of a function which accepts a request
Expand All @@ -22,3 +23,31 @@ export interface UserProfile {
name?: string;
email?: string;
}

export type Credentials = {
email: string;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the credentials include telephone number or username?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the credentials include telephone number or username?

#2246 - to be addressed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dreamdevil00 Good point. And #2246 is supposed to provide a solution for customizing the fields. (Thanks @dougal83 )

password: string;
};

export type AuthenticatedUser<U extends Entity> = {
authenticated: boolean;
userInfo?: U;
};

/**
* An interface describes the common authentication strategy.
*
* An authentication strategy is usually a class with an
* authenticate method that verifies a user's identity and
* returns the corresponding user profile.
*
* Please note this file should be moved to @loopback/authentication
*/
export interface AuthenticationStrategy {
authenticateRequest(request: Request): Promise<UserProfile | undefined>;
authenticateUser<U extends Entity>(
credentials: Credentials,
): Promise<AuthenticatedUser<U>>;
generateAccesstoken(user: UserProfile): Promise<string>;
decodeAccesstoken(token: string): Promise<UserProfile | undefined>;
}