1 | import { StrictUnion } from '../../types';
|
2 | import { AtLeastOne } from '../types';
|
3 | interface JwtPayloadStandardFields {
|
4 | exp?: number;
|
5 | iss?: string;
|
6 | aud?: string | string[];
|
7 | nbf?: number;
|
8 | iat?: number;
|
9 | scope?: string;
|
10 | jti?: string;
|
11 | sub?: string;
|
12 | }
|
13 | type JsonPrimitive = null | string | number | boolean;
|
14 |
|
15 | type JsonArray = (JsonPrimitive | JsonObject | JsonArray)[];
|
16 |
|
17 | interface JsonObject {
|
18 | [x: string]: JsonPrimitive | JsonArray | JsonObject;
|
19 | }
|
20 | export type JwtPayload = JwtPayloadStandardFields & JsonObject;
|
21 | export interface JWT {
|
22 | payload: JwtPayload;
|
23 | toString(): string;
|
24 | }
|
25 | export type JWTCreator = (stringJWT: string) => JWT;
|
26 | export interface AuthSession {
|
27 | tokens?: AuthTokens;
|
28 | credentials?: AWSCredentials;
|
29 | identityId?: string;
|
30 | userSub?: string;
|
31 | }
|
32 | export interface LibraryAuthOptions {
|
33 | tokenProvider?: TokenProvider;
|
34 | credentialsProvider?: CredentialsAndIdentityIdProvider;
|
35 | }
|
36 | export interface Identity {
|
37 | id: string;
|
38 | type: 'guest' | 'primary';
|
39 | }
|
40 | export interface CredentialsAndIdentityIdProvider {
|
41 | getCredentialsAndIdentityId(getCredentialsOptions: GetCredentialsOptions): Promise<CredentialsAndIdentityId | undefined>;
|
42 | clearCredentialsAndIdentityId(): void;
|
43 | }
|
44 | export interface TokenProvider {
|
45 | getTokens({ forceRefresh, }?: {
|
46 | forceRefresh?: boolean;
|
47 | }): Promise<AuthTokens | null>;
|
48 | }
|
49 | export interface FetchAuthSessionOptions {
|
50 | forceRefresh?: boolean;
|
51 | }
|
52 | export interface AuthTokens {
|
53 | idToken?: JWT;
|
54 | accessToken: JWT;
|
55 | |
56 |
|
57 |
|
58 |
|
59 | signInDetails?: AWSAuthSignInDetails;
|
60 | }
|
61 | export type AuthStandardAttributeKey = 'address' | 'birthdate' | 'email_verified' | 'family_name' | 'gender' | 'given_name' | 'locale' | 'middle_name' | 'name' | 'nickname' | 'phone_number_verified' | 'picture' | 'preferred_username' | 'profile' | 'sub' | 'updated_at' | 'website' | 'zoneinfo' | AuthVerifiableAttributeKey;
|
62 | export type LegacyUserAttributeKey = Uppercase<AuthStandardAttributeKey>;
|
63 | export type AuthVerifiableAttributeKey = 'email' | 'phone_number';
|
64 | type UserGroupName = string;
|
65 | type UserGroupPrecedence = Record<string, number>;
|
66 | export type AuthConfigUserAttributes = Partial<Record<AuthStandardAttributeKey, {
|
67 | required: boolean;
|
68 | }>>;
|
69 | export type AuthConfig = AtLeastOne<CognitoProviderConfig>;
|
70 | export type CognitoProviderConfig = StrictUnion<AuthIdentityPoolConfig | AuthUserPoolConfig | AuthUserPoolAndIdentityPoolConfig>;
|
71 | export interface AuthIdentityPoolConfig {
|
72 | Cognito: CognitoIdentityPoolConfig & {
|
73 | userPoolClientId?: never;
|
74 | userPoolId?: never;
|
75 | userPoolEndpoint?: never;
|
76 | loginWith?: never;
|
77 | signUpVerificationMethod?: never;
|
78 | userAttributes?: never;
|
79 | mfa?: never;
|
80 | passwordFormat?: never;
|
81 | groups?: never;
|
82 | };
|
83 | }
|
84 | export interface CognitoIdentityPoolConfig {
|
85 | identityPoolId: string;
|
86 | allowGuestAccess?: boolean;
|
87 | }
|
88 | export interface AuthUserPoolConfig {
|
89 | Cognito: CognitoUserPoolConfig & {
|
90 | identityPoolId?: never;
|
91 | allowGuestAccess?: never;
|
92 | };
|
93 | }
|
94 | export type CognitoUserPoolConfigMfaStatus = 'on' | 'off' | 'optional';
|
95 | export interface CognitoUserPoolConfig {
|
96 | userPoolClientId: string;
|
97 | userPoolId: string;
|
98 | userPoolEndpoint?: string;
|
99 | signUpVerificationMethod?: 'code' | 'link';
|
100 | loginWith?: {
|
101 | oauth?: OAuthConfig;
|
102 | username?: boolean;
|
103 | email?: boolean;
|
104 | phone?: boolean;
|
105 | };
|
106 | userAttributes?: AuthConfigUserAttributes;
|
107 | mfa?: {
|
108 | status?: CognitoUserPoolConfigMfaStatus;
|
109 | totpEnabled?: boolean;
|
110 | smsEnabled?: boolean;
|
111 | };
|
112 | passwordFormat?: {
|
113 | minLength?: number;
|
114 | requireLowercase?: boolean;
|
115 | requireUppercase?: boolean;
|
116 | requireNumbers?: boolean;
|
117 | requireSpecialCharacters?: boolean;
|
118 | };
|
119 | groups?: Record<UserGroupName, UserGroupPrecedence>[];
|
120 | }
|
121 | export interface OAuthConfig {
|
122 | domain: string;
|
123 | scopes: OAuthScope[];
|
124 | redirectSignIn: string[];
|
125 | redirectSignOut: string[];
|
126 | responseType: 'code' | 'token';
|
127 | providers?: (OAuthProvider | CustomProvider)[];
|
128 | }
|
129 | export type OAuthProvider = 'Google' | 'Facebook' | 'Amazon' | 'Apple';
|
130 | interface CustomProvider {
|
131 | custom: string;
|
132 | }
|
133 | type CustomScope = string & NonNullable<unknown>;
|
134 | export type OAuthScope = 'email' | 'openid' | 'phone' | 'profile' | 'aws.cognito.signin.user.admin' | CustomScope;
|
135 | export type CognitoUserPoolWithOAuthConfig = CognitoUserPoolConfig & {
|
136 | loginWith: {
|
137 | oauth: OAuthConfig;
|
138 | };
|
139 | };
|
140 | export interface AuthUserPoolAndIdentityPoolConfig {
|
141 | Cognito: CognitoUserPoolAndIdentityPoolConfig;
|
142 | }
|
143 | export type CognitoUserPoolAndIdentityPoolConfig = CognitoUserPoolConfig & CognitoIdentityPoolConfig;
|
144 | export type GetCredentialsOptions = GetCredentialsAuthenticatedUser | GetCredentialsUnauthenticatedUser;
|
145 | interface GetCredentialsAuthenticatedUser {
|
146 | authenticated: true;
|
147 | forceRefresh?: boolean;
|
148 | authConfig: AuthConfig | undefined;
|
149 | tokens: AuthTokens;
|
150 | }
|
151 | interface GetCredentialsUnauthenticatedUser {
|
152 | authenticated: false;
|
153 | forceRefresh?: boolean;
|
154 | authConfig: AuthConfig | undefined;
|
155 | tokens?: never;
|
156 | }
|
157 | export interface CredentialsAndIdentityId {
|
158 | credentials: AWSCredentials;
|
159 | identityId?: string;
|
160 | }
|
161 | export interface AWSCredentials {
|
162 | accessKeyId: string;
|
163 | secretAccessKey: string;
|
164 | sessionToken?: string;
|
165 | expiration?: Date;
|
166 | }
|
167 |
|
168 |
|
169 |
|
170 | interface AWSAuthSignInDetails {
|
171 | loginId?: string;
|
172 | authFlowType?: AuthFlowType;
|
173 | }
|
174 |
|
175 |
|
176 |
|
177 | type AuthFlowType = 'USER_AUTH' | 'USER_SRP_AUTH' | 'CUSTOM_WITH_SRP' | 'CUSTOM_WITHOUT_SRP' | 'USER_PASSWORD_AUTH';
|
178 | export {};
|