-
Notifications
You must be signed in to change notification settings - Fork 241
Expand file tree
/
Copy pathINativeBridge.ts
More file actions
186 lines (171 loc) · 6.46 KB
/
Copy pathINativeBridge.ts
File metadata and controls
186 lines (171 loc) · 6.46 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import type {
Credentials,
ApiCredentials,
WebAuthorizeParameters,
ClearSessionParameters,
DPoPHeadersParams,
SessionTransferCredentials,
} from '../../../types';
import type {
LocalAuthenticationOptions,
NativeAuthorizeOptions,
NativeClearSessionOptions,
} from '../../../types/platform-specific';
/**
* The contract defining all methods that the native-side module must implement.
* This interface is the single source of truth for communication between the
* JavaScript and the native layers (iOS/Android).
*/
export interface INativeBridge {
/**
* Checks if the native SDK has been initialized with the required credentials.
* This should be called before any other method.
*
* @returns A promise that resolves with true if initialized, false otherwise.
*/
hasValidInstance(clientId: string, domain: string): Promise<boolean>;
/**
* Initializes the native SDK with the required credentials.
* This should be called before any other method.
*
* @param clientId The Auth0 application client ID.
* @param domain The Auth0 application domain.
* @param localAuthenticationOptions Options for local authentication.
* @param useDPoP Whether to enable DPoP (Demonstrating Proof-of-Possession) for token requests.
*/
initialize(
clientId: string,
domain: string,
localAuthenticationOptions?: LocalAuthenticationOptions,
useDPoP?: boolean
): Promise<void>;
/**
* Retrieves the bundle identifier for the native application.
* @returns A promise that resolves with the bundle identifier as a string.
*/
getBundleIdentifier(): Promise<string>;
/**
* Triggers the native web-based authentication flow.
*
* @param parameters The parameters for the `/authorize` endpoint.
* @param options The native-specific options for the web-based flow.
* @returns A promise that resolves with the user's credentials.
*/
authorize(
parameters: WebAuthorizeParameters,
options: NativeAuthorizeOptions
): Promise<Credentials>;
/**
* Triggers the native web-based logout flow.
*
* @param parameters The parameters for the `/v2/logout` endpoint.
* @param options The native-specific options for the logout flow.
* @returns A promise that resolves when the logout is complete.
*/
clearSession(
parameters: ClearSessionParameters,
options: NativeClearSessionOptions
): Promise<void>;
/**
* Cancels an ongoing web authentication flow.
* @platform ios
*/
cancelWebAuth(): Promise<void>;
/**
* Saves credentials to the native secure storage (Keychain/EncryptedSharedPreferences).
* @param credentials The credentials to save.
*/
saveCredentials(credentials: Credentials): Promise<void>;
/**
* Retrieves credentials from secure storage. This method performs a token refresh
* if the access token is expired and a refresh token is available.
*
* @param scope The scopes to request during a token refresh.
* @param minTtl The minimum time-to-live (in seconds) for the access token.
* @param forceRefresh If true, forces a token refresh.
* @returns A promise that resolves with the credentials.
*/
getCredentials(
scope?: string,
minTtl?: number,
parameters?: object,
forceRefresh?: boolean
): Promise<Credentials>;
/**
* Checks if valid credentials exist in secure storage.
*
* @param minTtl The minimum time-to-live (in seconds) for the access token.
* @returns A promise that resolves with true if valid credentials exist.
*/
hasValidCredentials(minTtl?: number): Promise<boolean>;
/**
* Retrieves API-specific credentials from secure storage.
*
* @param audience The audience of the API.
* @param scope The scopes to request during a token refresh.
* @param minTtl The minimum time-to-live (in seconds) for the access token.
* @param parameters Additional parameters for the refresh request.
* @returns A promise that resolves with the API credentials.
*/
getApiCredentials(
audience: string,
scope?: string,
minTtl?: number,
parameters?: object
): Promise<ApiCredentials>;
/**
* Clears API credentials for a specific audience from secure storage.
* Optionally filter by scope to clear only specific scope-based credentials.
*
* @param audience The audience of the API.
* @param scope Optional scope to clear. If not provided, clears all credentials for the audience.
*/
clearApiCredentials(audience: string, scope?: string): Promise<void>;
/**
* Clears credentials from secure storage.
*/
clearCredentials(): Promise<void>;
/**
* Resumes the web authentication flow with the provided URL.
* @param url The URL to resume the authentication flow.
* @returns A promise that resolves when the flow has been resumed.
*/
resumeWebAuth(url: string): Promise<void>;
/**
* Generates DPoP headers for making authenticated requests to custom APIs.
* This method creates the necessary HTTP headers (Authorization and DPoP) to
* securely bind the access token to a specific API request.
*
* @param params Parameters including the URL, HTTP method, access token, and token type.
* @returns A promise that resolves to an object containing the required headers.
*/
getDPoPHeaders(params: DPoPHeadersParams): Promise<Record<string, string>>;
/**
* Clears the DPoP key from secure storage.
* This should be called during logout to ensure the key is removed.
*/
clearDPoPKey(): Promise<void>;
/**
* Obtains session transfer credentials for performing Native to Web SSO.
*
* @remarks
* This method exchanges the stored refresh token for a session transfer token
* that can be used to authenticate in web contexts without requiring the user
* to log in again. The session transfer token is short-lived and expires after
* a few minutes.
*
* If Refresh Token Rotation is enabled, this method will also update the stored
* credentials with new tokens (ID token and refresh token) returned from the
* token exchange.
*
* @param parameters Optional additional parameters to pass to the token exchange.
* @param headers Optional additional headers to include in the token exchange request.
* @returns A promise that resolves with the session transfer credentials.
*
* @see https://auth0.com/docs/authenticate/single-sign-on/native-to-web/configure-implement-native-to-web
*/
getSSOCredentials(
parameters?: Record<string, any>,
headers?: Record<string, string>
): Promise<SessionTransferCredentials>;
}