UNPKG

5.78 kBTypeScriptView Raw
1import { StrictUnion } from '../../types';
2import { AtLeastOne } from '../types';
3interface 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}
13type JsonPrimitive = null | string | number | boolean;
14/** JSON array type */
15type JsonArray = (JsonPrimitive | JsonObject | JsonArray)[];
16/** JSON Object type */
17interface JsonObject {
18 [x: string]: JsonPrimitive | JsonArray | JsonObject;
19}
20export type JwtPayload = JwtPayloadStandardFields & JsonObject;
21export interface JWT {
22 payload: JwtPayload;
23 toString(): string;
24}
25export type JWTCreator = (stringJWT: string) => JWT;
26export interface AuthSession {
27 tokens?: AuthTokens;
28 credentials?: AWSCredentials;
29 identityId?: string;
30 userSub?: string;
31}
32export interface LibraryAuthOptions {
33 tokenProvider?: TokenProvider;
34 credentialsProvider?: CredentialsAndIdentityIdProvider;
35}
36export interface Identity {
37 id: string;
38 type: 'guest' | 'primary';
39}
40export interface CredentialsAndIdentityIdProvider {
41 getCredentialsAndIdentityId(getCredentialsOptions: GetCredentialsOptions): Promise<CredentialsAndIdentityId | undefined>;
42 clearCredentialsAndIdentityId(): void;
43}
44export interface TokenProvider {
45 getTokens({ forceRefresh, }?: {
46 forceRefresh?: boolean;
47 }): Promise<AuthTokens | null>;
48}
49export interface FetchAuthSessionOptions {
50 forceRefresh?: boolean;
51}
52export interface AuthTokens {
53 idToken?: JWT;
54 accessToken: JWT;
55 /**
56 * @deprecated
57 * Use getCurrentUser to access signInDetails
58 */
59 signInDetails?: AWSAuthSignInDetails;
60}
61export 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;
62export type LegacyUserAttributeKey = Uppercase<AuthStandardAttributeKey>;
63export type AuthVerifiableAttributeKey = 'email' | 'phone_number';
64type UserGroupName = string;
65type UserGroupPrecedence = Record<string, number>;
66export type AuthConfigUserAttributes = Partial<Record<AuthStandardAttributeKey, {
67 required: boolean;
68}>>;
69export type AuthConfig = AtLeastOne<CognitoProviderConfig>;
70export type CognitoProviderConfig = StrictUnion<AuthIdentityPoolConfig | AuthUserPoolConfig | AuthUserPoolAndIdentityPoolConfig>;
71export 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}
84export interface CognitoIdentityPoolConfig {
85 identityPoolId: string;
86 allowGuestAccess?: boolean;
87}
88export interface AuthUserPoolConfig {
89 Cognito: CognitoUserPoolConfig & {
90 identityPoolId?: never;
91 allowGuestAccess?: never;
92 };
93}
94export type CognitoUserPoolConfigMfaStatus = 'on' | 'off' | 'optional';
95export 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}
121export interface OAuthConfig {
122 domain: string;
123 scopes: OAuthScope[];
124 redirectSignIn: string[];
125 redirectSignOut: string[];
126 responseType: 'code' | 'token';
127 providers?: (OAuthProvider | CustomProvider)[];
128}
129export type OAuthProvider = 'Google' | 'Facebook' | 'Amazon' | 'Apple';
130interface CustomProvider {
131 custom: string;
132}
133type CustomScope = string & NonNullable<unknown>;
134export type OAuthScope = 'email' | 'openid' | 'phone' | 'profile' | 'aws.cognito.signin.user.admin' | CustomScope;
135export type CognitoUserPoolWithOAuthConfig = CognitoUserPoolConfig & {
136 loginWith: {
137 oauth: OAuthConfig;
138 };
139};
140export interface AuthUserPoolAndIdentityPoolConfig {
141 Cognito: CognitoUserPoolAndIdentityPoolConfig;
142}
143export type CognitoUserPoolAndIdentityPoolConfig = CognitoUserPoolConfig & CognitoIdentityPoolConfig;
144export type GetCredentialsOptions = GetCredentialsAuthenticatedUser | GetCredentialsUnauthenticatedUser;
145interface GetCredentialsAuthenticatedUser {
146 authenticated: true;
147 forceRefresh?: boolean;
148 authConfig: AuthConfig | undefined;
149 tokens: AuthTokens;
150}
151interface GetCredentialsUnauthenticatedUser {
152 authenticated: false;
153 forceRefresh?: boolean;
154 authConfig: AuthConfig | undefined;
155 tokens?: never;
156}
157export interface CredentialsAndIdentityId {
158 credentials: AWSCredentials;
159 identityId?: string;
160}
161export interface AWSCredentials {
162 accessKeyId: string;
163 secretAccessKey: string;
164 sessionToken?: string;
165 expiration?: Date;
166}
167/**
168 * @deprecated
169 */
170interface AWSAuthSignInDetails {
171 loginId?: string;
172 authFlowType?: AuthFlowType;
173}
174/**
175 * @deprecated
176 */
177type AuthFlowType = 'USER_AUTH' | 'USER_SRP_AUTH' | 'CUSTOM_WITH_SRP' | 'CUSTOM_WITHOUT_SRP' | 'USER_PASSWORD_AUTH';
178export {};