Skip to content

Commit

Permalink
feat: allow user identifier to be string|number
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonraimondi committed Sep 22, 2021
1 parent c97f18c commit c779e6f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/entities/user.entity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export type OAuthUserIdentifier = string | number;

export interface OAuthUser {
id: string | number;
id: OAuthUserIdentifier;
[key: string]: any;
}
5 changes: 3 additions & 2 deletions src/grants/auth_code.grant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { CodeChallengeMethod, ICodeChallenge } from "../code_verifiers/verifier"
import { OAuthAuthCode } from "../entities/auth_code.entity";
import { OAuthClient } from "../entities/client.entity";
import { OAuthScope } from "../entities/scope.entity";
import { OAuthUserIdentifier } from "../entities/user.entity";
import { OAuthException } from "../exceptions/oauth.exception";
import { AuthorizationRequest } from "../requests/authorization.request";
import { RequestInterface } from "../requests/request";
Expand All @@ -18,7 +19,7 @@ export interface IAuthCodePayload {
auth_code_id: string;
expire_time: number;
scopes: string[];
user_id?: string | null;
user_id?: OAuthUserIdentifier | null;
redirect_uri?: string | null;
code_challenge?: string | null;
code_challenge_method?: CodeChallengeMethod | null;
Expand Down Expand Up @@ -252,7 +253,7 @@ export class AuthCodeGrant extends AbstractAuthorizedGrant {
private async issueAuthCode(
authCodeTTL: DateInterval,
client: OAuthClient,
userIdentifier?: string,
userIdentifier?: OAuthUserIdentifier,
redirectUri?: string,
codeChallenge?: string,
codeChallengeMethod?: CodeChallengeMethod,
Expand Down
3 changes: 2 additions & 1 deletion src/repositories/scope.repository.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { OAuthClient } from "../entities/client.entity";
import { OAuthScope } from "../entities/scope.entity";
import { OAuthUserIdentifier } from "../entities/user.entity";
import { GrantIdentifier } from "../grants/abstract/grant.interface";

export interface OAuthScopeRepository {
Expand All @@ -9,6 +10,6 @@ export interface OAuthScopeRepository {
scopes: OAuthScope[],
identifier: GrantIdentifier,
client: OAuthClient,
user_id?: string,
user_id?: OAuthUserIdentifier,
): Promise<OAuthScope[]>;
}
4 changes: 2 additions & 2 deletions src/repositories/user.repository.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { OAuthClient } from "../entities/client.entity";
import { OAuthUser } from "../entities/user.entity";
import { OAuthUser, OAuthUserIdentifier } from "../entities/user.entity";
import { GrantIdentifier } from "../grants/abstract/grant.interface";

export type ExtraAccessTokenFields = Record<string, string | number | boolean>;

export interface OAuthUserRepository {
getUserByCredentials(
identifier: string,
identifier: OAuthUserIdentifier,
password?: string,
grantType?: GrantIdentifier,
client?: OAuthClient,
Expand Down

0 comments on commit c779e6f

Please sign in to comment.