-
Notifications
You must be signed in to change notification settings - Fork 213
/
Copy pathauth0.ts
61 lines (57 loc) · 2.19 KB
/
auth0.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import Auth from './auth';
import CredentialsManager from './credentials-manager';
import Users from './management/users';
import { Telemetry } from './networking/telemetry';
import WebAuth from './webauth';
import LocalAuthenticationOptions from './credentials-manager/localAuthenticationOptions';
import addDefaultLocalAuthOptions from './utils/addDefaultLocalAuthOptions';
/**
* Auth0 for React Native client
*/
class Auth0 {
public auth: Auth;
public webAuth: WebAuth;
public credentialsManager: CredentialsManager;
private options;
/**
* Creates an instance of Auth0.
* @param {Object} options Your Auth0 application information
* @param {String} options.domain Your Auth0 domain
* @param {String} options.clientId Your Auth0 application client identifier
* @param {String} options.telemetry The telemetry information to be sent along with the requests
* @param {String} options.token Token to be used for Management APIs
* @param {String} options.timeout Timeout to be set for requests.
* @param {LocalAuthenticationOptions} options.localAuthenticationOptions The options for configuring the display of local authentication prompt, authentication level (Android only) and evaluation policy (iOS only).
*/
constructor(options: {
domain: string;
clientId: string;
telemetry?: Telemetry;
token?: string;
timeout?: number;
localAuthenticationOptions?: LocalAuthenticationOptions;
}) {
const { domain, clientId, ...extras } = options;
const localAuthenticationOptions = options.localAuthenticationOptions
? addDefaultLocalAuthOptions(options.localAuthenticationOptions)
: undefined;
this.auth = new Auth({ baseUrl: domain, clientId, ...extras });
this.webAuth = new WebAuth(this.auth, localAuthenticationOptions);
this.credentialsManager = new CredentialsManager(
domain,
clientId,
localAuthenticationOptions
);
this.options = options;
}
/**
* Creates a Users API client
* @param {String} token for Management API
* @return {Users}
*/
users(token: string) {
const { domain, ...extras } = this.options;
return new Users({ baseUrl: domain, ...extras, token });
}
}
export default Auth0;