1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | import {
|
15 | ICookieStorageData,
|
16 | ICognitoStorage,
|
17 | } from 'amazon-cognito-identity-js';
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | export interface SignUpParams {
|
23 | username: string;
|
24 | password: string;
|
25 | attributes?: object;
|
26 | validationData?: { [key: string]: any };
|
27 | clientMetadata?: { [key: string]: string };
|
28 | }
|
29 |
|
30 | export interface AuthCache {
|
31 | setItem();
|
32 | getItem();
|
33 | removeItem();
|
34 | }
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | export interface AuthOptions {
|
40 | userPoolId?: string;
|
41 | userPoolWebClientId?: string;
|
42 | identityPoolId?: string;
|
43 | region?: string;
|
44 | mandatorySignIn?: boolean;
|
45 | cookieStorage?: ICookieStorageData;
|
46 | oauth?: OAuthOpts;
|
47 | refreshHandlers?: object;
|
48 | storage?: ICognitoStorage;
|
49 | authenticationFlowType?: string;
|
50 | identityPoolRegion?: string;
|
51 | clientMetadata?: any;
|
52 | endpoint?: string;
|
53 | }
|
54 |
|
55 | export enum CognitoHostedUIIdentityProvider {
|
56 | Cognito = 'COGNITO',
|
57 | Google = 'Google',
|
58 | Facebook = 'Facebook',
|
59 | Amazon = 'LoginWithAmazon',
|
60 | Apple = 'SignInWithApple',
|
61 | }
|
62 |
|
63 | export type LegacyProvider =
|
64 | | 'google'
|
65 | | 'facebook'
|
66 | | 'amazon'
|
67 | | 'developer'
|
68 | | string;
|
69 |
|
70 | export type FederatedSignInOptions = {
|
71 | provider: CognitoHostedUIIdentityProvider;
|
72 | customState?: string;
|
73 | };
|
74 |
|
75 | export type FederatedSignInOptionsCustom = {
|
76 | customProvider: string;
|
77 | customState?: string;
|
78 | };
|
79 |
|
80 | export function isFederatedSignInOptions(
|
81 | obj: any
|
82 | ): obj is FederatedSignInOptions {
|
83 | const keys: (keyof FederatedSignInOptions)[] = ['provider'];
|
84 | return obj && !!keys.find(k => obj.hasOwnProperty(k));
|
85 | }
|
86 |
|
87 | export function isFederatedSignInOptionsCustom(
|
88 | obj: any
|
89 | ): obj is FederatedSignInOptionsCustom {
|
90 | const keys: (keyof FederatedSignInOptionsCustom)[] = ['customProvider'];
|
91 | return obj && !!keys.find(k => obj.hasOwnProperty(k));
|
92 | }
|
93 |
|
94 | export function hasCustomState(obj: any): boolean {
|
95 | const keys: (keyof (
|
96 | | FederatedSignInOptions
|
97 | | FederatedSignInOptionsCustom
|
98 | ))[] = ['customState'];
|
99 | return obj && !!keys.find(k => obj.hasOwnProperty(k));
|
100 | }
|
101 |
|
102 |
|
103 |
|
104 |
|
105 | export interface MfaRequiredDetails {
|
106 | challengeName: any;
|
107 | challengeParameters: any;
|
108 | }
|
109 |
|
110 |
|
111 |
|
112 |
|
113 | export interface FederatedResponse {
|
114 |
|
115 | token: string;
|
116 |
|
117 | identity_id?: string;
|
118 |
|
119 | expires_at: number;
|
120 | }
|
121 |
|
122 |
|
123 |
|
124 |
|
125 | export interface FederatedUser {
|
126 | name: string;
|
127 | email?: string;
|
128 | picture?: string;
|
129 | }
|
130 |
|
131 | export interface AwsCognitoOAuthOpts {
|
132 | domain: string;
|
133 | scope: Array<string>;
|
134 | redirectSignIn: string;
|
135 | redirectSignOut: string;
|
136 | responseType: string;
|
137 | options?: object;
|
138 | urlOpener?: (url: string, redirectUrl: string) => Promise<any>;
|
139 | }
|
140 |
|
141 | export function isCognitoHostedOpts(
|
142 | oauth: OAuthOpts
|
143 | ): oauth is AwsCognitoOAuthOpts {
|
144 | return (<AwsCognitoOAuthOpts>oauth).redirectSignIn !== undefined;
|
145 | }
|
146 |
|
147 | export interface Auth0OAuthOpts {
|
148 | domain: string;
|
149 | clientID: string;
|
150 | scope: string;
|
151 | redirectUri: string;
|
152 | audience: string;
|
153 | responseType: string;
|
154 | returnTo: string;
|
155 | urlOpener?: (url: string, redirectUrl: string) => Promise<any>;
|
156 | }
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 | export type OAuthOpts = AwsCognitoOAuthOpts | Auth0OAuthOpts;
|
165 |
|
166 | export interface ConfirmSignUpOptions {
|
167 | forceAliasCreation?: boolean;
|
168 | clientMetadata?: ClientMetaData;
|
169 | }
|
170 |
|
171 | export interface SignOutOpts {
|
172 | global?: boolean;
|
173 | }
|
174 |
|
175 | export interface CurrentUserOpts {
|
176 | bypassCache: boolean;
|
177 | }
|
178 |
|
179 | export interface GetPreferredMFAOpts {
|
180 | bypassCache: boolean;
|
181 | }
|
182 |
|
183 | export type UsernamePasswordOpts = {
|
184 | username: string;
|
185 | password: string;
|
186 | validationData?: { [key: string]: any };
|
187 | };
|
188 |
|
189 | export enum AuthErrorTypes {
|
190 | NoConfig = 'noConfig',
|
191 | MissingAuthConfig = 'missingAuthConfig',
|
192 | EmptyUsername = 'emptyUsername',
|
193 | InvalidUsername = 'invalidUsername',
|
194 | EmptyPassword = 'emptyPassword',
|
195 | EmptyCode = 'emptyCode',
|
196 | SignUpError = 'signUpError',
|
197 | NoMFA = 'noMFA',
|
198 | InvalidMFA = 'invalidMFA',
|
199 | EmptyChallengeResponse = 'emptyChallengeResponse',
|
200 | NoUserSession = 'noUserSession',
|
201 | Default = 'default',
|
202 | DeviceConfig = 'deviceConfig',
|
203 | NetworkError = 'networkError',
|
204 | }
|
205 |
|
206 | export type AuthErrorMessages = { [key in AuthErrorTypes]: AuthErrorMessage };
|
207 |
|
208 | export interface AuthErrorMessage {
|
209 | message: string;
|
210 | log?: string;
|
211 | }
|
212 |
|
213 |
|
214 | export type SignInOpts = UsernamePasswordOpts;
|
215 |
|
216 | export type ClientMetaData =
|
217 | | {
|
218 | [key: string]: string;
|
219 | }
|
220 | | undefined;
|
221 |
|
222 | export function isUsernamePasswordOpts(obj: any): obj is UsernamePasswordOpts {
|
223 | return !!(obj as UsernamePasswordOpts).username;
|
224 | }
|
225 |
|
226 | export interface IAuthDevice {
|
227 | id: string;
|
228 | name: string;
|
229 | }
|
230 |
|
231 | export enum GRAPHQL_AUTH_MODE {
|
232 | API_KEY = 'API_KEY',
|
233 | AWS_IAM = 'AWS_IAM',
|
234 | OPENID_CONNECT = 'OPENID_CONNECT',
|
235 | AMAZON_COGNITO_USER_POOLS = 'AMAZON_COGNITO_USER_POOLS',
|
236 | AWS_LAMBDA = 'AWS_LAMBDA',
|
237 | }
|