@symbiote-native/auth-session 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +157 -2
- package/build/angular/index.d.ts +2 -0
- package/build/angular/index.js +3 -0
- package/build/angular/use-auth-request.d.ts +7 -0
- package/build/angular/use-auth-request.js +11 -0
- package/build/core/auth-request-controllers.d.ts +44 -0
- package/build/core/auth-request-controllers.js +122 -0
- package/build/core/auth-request-hooks.d.ts +67 -0
- package/build/core/auth-request-hooks.js +75 -0
- package/build/core/auth-request.d.ts +29 -0
- package/build/core/auth-request.js +161 -0
- package/build/core/auth-request.types.d.ts +46 -0
- package/build/core/auth-request.types.js +23 -0
- package/build/core/auth-session.d.ts +10 -0
- package/build/core/auth-session.js +37 -0
- package/build/core/auth-session.types.d.ts +27 -0
- package/build/core/auth-session.types.js +1 -0
- package/build/core/base64.d.ts +1 -0
- package/build/core/base64.js +28 -0
- package/build/core/discovery.d.ts +57 -0
- package/build/core/discovery.js +29 -0
- package/build/core/errors.d.ts +29 -0
- package/build/core/errors.js +74 -0
- package/build/core/fetch.d.ts +15 -0
- package/build/core/fetch.js +40 -0
- package/build/core/index.d.ts +24 -0
- package/build/core/index.js +14 -0
- package/build/core/pkce.d.ts +9 -0
- package/build/core/pkce.js +41 -0
- package/build/core/prompt-string.d.ts +2 -0
- package/build/core/prompt-string.js +5 -0
- package/build/core/providers/facebook.d.ts +16 -0
- package/build/core/providers/facebook.js +43 -0
- package/build/core/providers/google-exchange-controller.d.ts +10 -0
- package/build/core/providers/google-exchange-controller.js +73 -0
- package/build/core/providers/google.d.ts +22 -0
- package/build/core/providers/google.js +52 -0
- package/build/core/providers/provider-hook-setup.d.ts +19 -0
- package/build/core/providers/provider-hook-setup.js +78 -0
- package/build/core/providers/provider-utils.d.ts +2 -0
- package/build/core/providers/provider-utils.js +8 -0
- package/build/core/providers/provider.types.d.ts +5 -0
- package/build/core/providers/provider.types.js +1 -0
- package/build/core/query-params.d.ts +5 -0
- package/build/core/query-params.js +12 -0
- package/build/core/session-result.d.ts +6 -0
- package/build/core/session-result.js +4 -0
- package/build/core/token-request.d.ts +89 -0
- package/build/core/token-request.js +328 -0
- package/build/core/token-request.types.d.ts +52 -0
- package/build/core/token-request.types.js +14 -0
- package/build/react/index.d.ts +3 -0
- package/build/react/index.js +2 -0
- package/build/react/use-auth-request.d.ts +20 -0
- package/build/react/use-auth-request.js +52 -0
- package/build/solid/index.d.ts +2 -0
- package/build/solid/index.js +2 -0
- package/build/solid/use-auth-request.d.ts +6 -0
- package/build/solid/use-auth-request.js +10 -0
- package/build/svelte/index.d.ts +2 -0
- package/build/svelte/index.js +2 -0
- package/build/svelte/use-auth-request.svelte.d.ts +28 -0
- package/build/svelte/use-auth-request.svelte.js +11 -0
- package/build/vue/index.d.ts +2 -0
- package/build/vue/index.js +2 -0
- package/build/vue/use-auth-request.d.ts +7 -0
- package/build/vue/use-auth-request.js +12 -0
- package/build-ngc/angular/index.d.ts +2 -0
- package/build-ngc/angular/index.js +4 -0
- package/build-ngc/angular/index.js.map +1 -0
- package/build-ngc/angular/use-auth-request.d.ts +7 -0
- package/build-ngc/angular/use-auth-request.js +12 -0
- package/build-ngc/angular/use-auth-request.js.map +1 -0
- package/build-ngc/core/auth-request-controllers.d.ts +44 -0
- package/build-ngc/core/auth-request-controllers.js +123 -0
- package/build-ngc/core/auth-request-controllers.js.map +1 -0
- package/build-ngc/core/auth-request-hooks.d.ts +67 -0
- package/build-ngc/core/auth-request-hooks.js +76 -0
- package/build-ngc/core/auth-request-hooks.js.map +1 -0
- package/build-ngc/core/auth-request.d.ts +29 -0
- package/build-ngc/core/auth-request.js +162 -0
- package/build-ngc/core/auth-request.js.map +1 -0
- package/build-ngc/core/auth-request.types.d.ts +46 -0
- package/build-ngc/core/auth-request.types.js +24 -0
- package/build-ngc/core/auth-request.types.js.map +1 -0
- package/build-ngc/core/auth-session.d.ts +10 -0
- package/build-ngc/core/auth-session.js +38 -0
- package/build-ngc/core/auth-session.js.map +1 -0
- package/build-ngc/core/auth-session.types.d.ts +27 -0
- package/build-ngc/core/auth-session.types.js +2 -0
- package/build-ngc/core/auth-session.types.js.map +1 -0
- package/build-ngc/core/base64.d.ts +1 -0
- package/build-ngc/core/base64.js +29 -0
- package/build-ngc/core/base64.js.map +1 -0
- package/build-ngc/core/discovery.d.ts +57 -0
- package/build-ngc/core/discovery.js +30 -0
- package/build-ngc/core/discovery.js.map +1 -0
- package/build-ngc/core/errors.d.ts +29 -0
- package/build-ngc/core/errors.js +75 -0
- package/build-ngc/core/errors.js.map +1 -0
- package/build-ngc/core/fetch.d.ts +15 -0
- package/build-ngc/core/fetch.js +41 -0
- package/build-ngc/core/fetch.js.map +1 -0
- package/build-ngc/core/index.d.ts +24 -0
- package/build-ngc/core/index.js +15 -0
- package/build-ngc/core/index.js.map +1 -0
- package/build-ngc/core/pkce.d.ts +9 -0
- package/build-ngc/core/pkce.js +42 -0
- package/build-ngc/core/pkce.js.map +1 -0
- package/build-ngc/core/prompt-string.d.ts +2 -0
- package/build-ngc/core/prompt-string.js +6 -0
- package/build-ngc/core/prompt-string.js.map +1 -0
- package/build-ngc/core/providers/facebook.d.ts +16 -0
- package/build-ngc/core/providers/facebook.js +44 -0
- package/build-ngc/core/providers/facebook.js.map +1 -0
- package/build-ngc/core/providers/google-exchange-controller.d.ts +10 -0
- package/build-ngc/core/providers/google-exchange-controller.js +74 -0
- package/build-ngc/core/providers/google-exchange-controller.js.map +1 -0
- package/build-ngc/core/providers/google.d.ts +22 -0
- package/build-ngc/core/providers/google.js +53 -0
- package/build-ngc/core/providers/google.js.map +1 -0
- package/build-ngc/core/providers/provider-hook-setup.d.ts +19 -0
- package/build-ngc/core/providers/provider-hook-setup.js +79 -0
- package/build-ngc/core/providers/provider-hook-setup.js.map +1 -0
- package/build-ngc/core/providers/provider-utils.d.ts +2 -0
- package/build-ngc/core/providers/provider-utils.js +9 -0
- package/build-ngc/core/providers/provider-utils.js.map +1 -0
- package/build-ngc/core/providers/provider.types.d.ts +5 -0
- package/build-ngc/core/providers/provider.types.js +2 -0
- package/build-ngc/core/providers/provider.types.js.map +1 -0
- package/build-ngc/core/query-params.d.ts +5 -0
- package/build-ngc/core/query-params.js +13 -0
- package/build-ngc/core/query-params.js.map +1 -0
- package/build-ngc/core/session-result.d.ts +6 -0
- package/build-ngc/core/session-result.js +5 -0
- package/build-ngc/core/session-result.js.map +1 -0
- package/build-ngc/core/token-request.d.ts +89 -0
- package/build-ngc/core/token-request.js +329 -0
- package/build-ngc/core/token-request.js.map +1 -0
- package/build-ngc/core/token-request.types.d.ts +52 -0
- package/build-ngc/core/token-request.types.js +15 -0
- package/build-ngc/core/token-request.types.js.map +1 -0
- package/package.json +151 -3
- package/src/angular/index.ts +11 -0
- package/src/angular/use-auth-request.ts +30 -0
- package/src/core/auth-request-controllers.ts +233 -0
- package/src/core/auth-request-hooks.ts +342 -0
- package/src/core/auth-request.ts +199 -0
- package/src/core/auth-request.types.ts +55 -0
- package/src/core/auth-session.ts +63 -0
- package/src/core/auth-session.types.ts +29 -0
- package/src/core/base64.ts +33 -0
- package/src/core/discovery.ts +102 -0
- package/src/core/errors.ts +102 -0
- package/src/core/fetch.ts +71 -0
- package/src/core/index.ts +97 -0
- package/src/core/pkce.ts +60 -0
- package/src/core/prompt-string.ts +8 -0
- package/src/core/providers/facebook.ts +66 -0
- package/src/core/providers/google-exchange-controller.ts +117 -0
- package/src/core/providers/google.ts +81 -0
- package/src/core/providers/provider-hook-setup.ts +117 -0
- package/src/core/providers/provider-utils.ts +18 -0
- package/src/core/providers/provider.types.ts +6 -0
- package/src/core/query-params.ts +20 -0
- package/src/core/session-result.ts +15 -0
- package/src/core/token-request.ts +452 -0
- package/src/core/token-request.types.ts +60 -0
- package/src/react/index.ts +11 -0
- package/src/react/use-auth-request.ts +151 -0
- package/src/solid/index.ts +10 -0
- package/src/solid/use-auth-request.ts +24 -0
- package/src/svelte/index.ts +10 -0
- package/src/svelte/svelte-ambient.d.ts +3 -0
- package/src/svelte/svelte-compile.test-helper.ts +7 -0
- package/src/svelte/use-auth-request.svelte.ts +22 -0
- package/src/vue/index.ts +10 -0
- package/src/vue/use-auth-request.ts +38 -0
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import invariant from 'invariant';
|
|
2
|
+
import * as Base64 from './base64.js';
|
|
3
|
+
import { TokenError } from './errors.js';
|
|
4
|
+
import { requestAsync } from './fetch.js';
|
|
5
|
+
import { GrantType } from './token-request.types.js';
|
|
6
|
+
export function getCurrentTimeInSeconds() {
|
|
7
|
+
return Math.floor(Date.now() / 1000);
|
|
8
|
+
}
|
|
9
|
+
function asTokenType(value) {
|
|
10
|
+
return value === 'bearer' || value === 'mac' ? value : undefined;
|
|
11
|
+
}
|
|
12
|
+
/** https://tools.ietf.org/html/rfc6749#section-5.1 */
|
|
13
|
+
export class TokenResponse {
|
|
14
|
+
static isTokenFresh(token,
|
|
15
|
+
/** -10 minutes in seconds. */
|
|
16
|
+
secondsMargin = 60 * 10 * -1) {
|
|
17
|
+
if (!token) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
if (token.expiresIn) {
|
|
21
|
+
const now = getCurrentTimeInSeconds();
|
|
22
|
+
return now < token.issuedAt + token.expiresIn + secondsMargin;
|
|
23
|
+
}
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
static fromQueryParams(params) {
|
|
27
|
+
return new TokenResponse({
|
|
28
|
+
accessToken: params.access_token ?? '',
|
|
29
|
+
refreshToken: params.refresh_token,
|
|
30
|
+
scope: params.scope,
|
|
31
|
+
state: params.state,
|
|
32
|
+
idToken: params.id_token,
|
|
33
|
+
tokenType: asTokenType(params.token_type),
|
|
34
|
+
expiresIn: params.expires_in ? Number(params.expires_in) : undefined,
|
|
35
|
+
issuedAt: params.issued_at ? Number(params.issued_at) : undefined,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
accessToken;
|
|
39
|
+
tokenType;
|
|
40
|
+
expiresIn;
|
|
41
|
+
refreshToken;
|
|
42
|
+
scope;
|
|
43
|
+
state;
|
|
44
|
+
idToken;
|
|
45
|
+
issuedAt;
|
|
46
|
+
/** Unprocessed token response, for fields outside RFC 6749. */
|
|
47
|
+
rawResponse;
|
|
48
|
+
constructor(response, rawResponse) {
|
|
49
|
+
this.rawResponse = rawResponse;
|
|
50
|
+
this.accessToken = response.accessToken;
|
|
51
|
+
this.tokenType = response.tokenType ?? 'bearer';
|
|
52
|
+
this.expiresIn = response.expiresIn;
|
|
53
|
+
this.refreshToken = response.refreshToken;
|
|
54
|
+
this.scope = response.scope;
|
|
55
|
+
this.state = response.state;
|
|
56
|
+
this.idToken = response.idToken;
|
|
57
|
+
this.issuedAt = response.issuedAt ?? getCurrentTimeInSeconds();
|
|
58
|
+
}
|
|
59
|
+
applyResponseConfig(response) {
|
|
60
|
+
this.accessToken = response.accessToken ?? this.accessToken;
|
|
61
|
+
this.tokenType = response.tokenType ?? this.tokenType ?? 'bearer';
|
|
62
|
+
this.expiresIn = response.expiresIn ?? this.expiresIn;
|
|
63
|
+
this.refreshToken = response.refreshToken ?? this.refreshToken;
|
|
64
|
+
this.scope = response.scope ?? this.scope;
|
|
65
|
+
this.state = response.state ?? this.state;
|
|
66
|
+
this.idToken = response.idToken ?? this.idToken;
|
|
67
|
+
this.issuedAt =
|
|
68
|
+
response.issuedAt ?? this.issuedAt ?? getCurrentTimeInSeconds();
|
|
69
|
+
}
|
|
70
|
+
getRequestConfig() {
|
|
71
|
+
return {
|
|
72
|
+
accessToken: this.accessToken,
|
|
73
|
+
idToken: this.idToken,
|
|
74
|
+
refreshToken: this.refreshToken,
|
|
75
|
+
scope: this.scope,
|
|
76
|
+
state: this.state,
|
|
77
|
+
tokenType: this.tokenType,
|
|
78
|
+
issuedAt: this.issuedAt,
|
|
79
|
+
expiresIn: this.expiresIn,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
async refreshAsync(config, discovery) {
|
|
83
|
+
const request = new RefreshTokenRequest({
|
|
84
|
+
...config,
|
|
85
|
+
refreshToken: this.refreshToken,
|
|
86
|
+
});
|
|
87
|
+
const response = await request.performAsync(discovery);
|
|
88
|
+
response.refreshToken = response.refreshToken ?? this.refreshToken;
|
|
89
|
+
this.applyResponseConfig(response.getRequestConfig());
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
shouldRefresh() {
|
|
93
|
+
return !(TokenResponse.isTokenFresh(this) || !this.refreshToken);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function sanitizeExtraHeaders(extra, hasClientSecret) {
|
|
97
|
+
if (!extra) {
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
const extraHeaders = { ...extra };
|
|
101
|
+
delete extraHeaders['Content-Type'];
|
|
102
|
+
delete extraHeaders['content-type'];
|
|
103
|
+
if (hasClientSecret) {
|
|
104
|
+
delete extraHeaders.authorization;
|
|
105
|
+
delete extraHeaders.Authorization;
|
|
106
|
+
}
|
|
107
|
+
return extraHeaders;
|
|
108
|
+
}
|
|
109
|
+
function encodeBasicAuth(clientId, clientSecret) {
|
|
110
|
+
const credentials = `${encodeURIComponent(clientId)}:${encodeURIComponent(clientSecret)}`;
|
|
111
|
+
return Base64.encodeNoWrap(credentials);
|
|
112
|
+
}
|
|
113
|
+
class BaseRequest {
|
|
114
|
+
request;
|
|
115
|
+
constructor(request) {
|
|
116
|
+
this.request = request;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/** A generic token request. */
|
|
120
|
+
export class TokenRequest extends BaseRequest {
|
|
121
|
+
grantType;
|
|
122
|
+
clientId;
|
|
123
|
+
clientSecret;
|
|
124
|
+
scopes;
|
|
125
|
+
extraParams;
|
|
126
|
+
extraHeaders;
|
|
127
|
+
constructor(request, grantType) {
|
|
128
|
+
super(request);
|
|
129
|
+
this.grantType = grantType;
|
|
130
|
+
this.clientId = request.clientId;
|
|
131
|
+
this.clientSecret = request.clientSecret;
|
|
132
|
+
this.extraParams = request.extraParams;
|
|
133
|
+
this.scopes = request.scopes;
|
|
134
|
+
this.extraHeaders = sanitizeExtraHeaders(request.extraHeaders, typeof request.clientSecret !== 'undefined');
|
|
135
|
+
}
|
|
136
|
+
getHeaders() {
|
|
137
|
+
const headers = {
|
|
138
|
+
...this.extraHeaders,
|
|
139
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
140
|
+
};
|
|
141
|
+
if (typeof this.clientSecret !== 'undefined') {
|
|
142
|
+
headers.Authorization = `Basic ${encodeBasicAuth(this.clientId, this.clientSecret)}`;
|
|
143
|
+
}
|
|
144
|
+
return headers;
|
|
145
|
+
}
|
|
146
|
+
async performAsync(discovery) {
|
|
147
|
+
invariant(discovery.tokenEndpoint, 'Cannot invoke `performAsync()` without a valid tokenEndpoint');
|
|
148
|
+
const response = await requestAsync(discovery.tokenEndpoint, {
|
|
149
|
+
dataType: 'json',
|
|
150
|
+
method: 'POST',
|
|
151
|
+
headers: this.getHeaders(),
|
|
152
|
+
body: this.getQueryBody(),
|
|
153
|
+
});
|
|
154
|
+
if ('error' in response) {
|
|
155
|
+
throw new TokenError(response);
|
|
156
|
+
}
|
|
157
|
+
return new TokenResponse({
|
|
158
|
+
accessToken: response.access_token,
|
|
159
|
+
tokenType: response.token_type,
|
|
160
|
+
expiresIn: response.expires_in,
|
|
161
|
+
refreshToken: response.refresh_token,
|
|
162
|
+
scope: response.scope,
|
|
163
|
+
idToken: response.id_token,
|
|
164
|
+
issuedAt: response.issued_at,
|
|
165
|
+
}, response);
|
|
166
|
+
}
|
|
167
|
+
getRequestConfig() {
|
|
168
|
+
return this.request;
|
|
169
|
+
}
|
|
170
|
+
getQueryBody() {
|
|
171
|
+
const queryBody = { grant_type: this.grantType };
|
|
172
|
+
if (!this.clientSecret) {
|
|
173
|
+
queryBody.client_id = this.clientId;
|
|
174
|
+
}
|
|
175
|
+
if (this.scopes) {
|
|
176
|
+
queryBody.scope = this.scopes.join(' ');
|
|
177
|
+
}
|
|
178
|
+
for (const extra in this.extraParams) {
|
|
179
|
+
const param = this.extraParams[extra];
|
|
180
|
+
if (param != null && !(extra in queryBody)) {
|
|
181
|
+
queryBody[extra] = param;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return queryBody;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
/** https://tools.ietf.org/html/rfc6749#section-4.1.3 */
|
|
188
|
+
export class AccessTokenRequest extends TokenRequest {
|
|
189
|
+
code;
|
|
190
|
+
redirectUri;
|
|
191
|
+
constructor(options) {
|
|
192
|
+
invariant(options.redirectUri, '`AccessTokenRequest` requires a valid `redirectUri`.');
|
|
193
|
+
invariant(options.code, '`AccessTokenRequest` requires a valid authorization `code`.');
|
|
194
|
+
super(options, GrantType.AuthorizationCode);
|
|
195
|
+
this.code = options.code;
|
|
196
|
+
this.redirectUri = options.redirectUri;
|
|
197
|
+
}
|
|
198
|
+
getQueryBody() {
|
|
199
|
+
return {
|
|
200
|
+
...super.getQueryBody(),
|
|
201
|
+
redirect_uri: this.redirectUri,
|
|
202
|
+
code: this.code,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
getRequestConfig() {
|
|
206
|
+
return {
|
|
207
|
+
clientId: this.clientId,
|
|
208
|
+
clientSecret: this.clientSecret,
|
|
209
|
+
grantType: this.grantType,
|
|
210
|
+
code: this.code,
|
|
211
|
+
redirectUri: this.redirectUri,
|
|
212
|
+
extraParams: this.extraParams,
|
|
213
|
+
extraHeaders: this.extraHeaders,
|
|
214
|
+
scopes: this.scopes,
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
/** https://tools.ietf.org/html/rfc6749#section-6 */
|
|
219
|
+
export class RefreshTokenRequest extends TokenRequest {
|
|
220
|
+
refreshToken;
|
|
221
|
+
constructor(options) {
|
|
222
|
+
invariant(options.refreshToken, '`RefreshTokenRequest` requires a valid `refreshToken`.');
|
|
223
|
+
super(options, GrantType.RefreshToken);
|
|
224
|
+
this.refreshToken = options.refreshToken;
|
|
225
|
+
}
|
|
226
|
+
getQueryBody() {
|
|
227
|
+
const queryBody = super.getQueryBody();
|
|
228
|
+
if (this.refreshToken) {
|
|
229
|
+
queryBody.refresh_token = this.refreshToken;
|
|
230
|
+
}
|
|
231
|
+
return queryBody;
|
|
232
|
+
}
|
|
233
|
+
getRequestConfig() {
|
|
234
|
+
return {
|
|
235
|
+
clientId: this.clientId,
|
|
236
|
+
clientSecret: this.clientSecret,
|
|
237
|
+
grantType: this.grantType,
|
|
238
|
+
refreshToken: this.refreshToken,
|
|
239
|
+
extraParams: this.extraParams,
|
|
240
|
+
extraHeaders: this.extraHeaders,
|
|
241
|
+
scopes: this.scopes,
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
/** https://tools.ietf.org/html/rfc7009#section-2.1 */
|
|
246
|
+
export class RevokeTokenRequest extends BaseRequest {
|
|
247
|
+
clientId;
|
|
248
|
+
clientSecret;
|
|
249
|
+
token;
|
|
250
|
+
tokenTypeHint;
|
|
251
|
+
extraHeaders;
|
|
252
|
+
constructor(request) {
|
|
253
|
+
super(request);
|
|
254
|
+
invariant(request.token, '`RevokeTokenRequest` requires a valid `token` to revoke.');
|
|
255
|
+
this.clientId = request.clientId;
|
|
256
|
+
this.clientSecret = request.clientSecret;
|
|
257
|
+
this.token = request.token;
|
|
258
|
+
this.tokenTypeHint = request.tokenTypeHint;
|
|
259
|
+
this.extraHeaders = sanitizeExtraHeaders(request.extraHeaders, typeof request.clientSecret !== 'undefined');
|
|
260
|
+
}
|
|
261
|
+
getHeaders() {
|
|
262
|
+
const headers = {
|
|
263
|
+
...this.extraHeaders,
|
|
264
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
265
|
+
};
|
|
266
|
+
if (typeof this.clientSecret !== 'undefined' && this.clientId) {
|
|
267
|
+
headers.Authorization = `Basic ${encodeBasicAuth(this.clientId, this.clientSecret)}`;
|
|
268
|
+
}
|
|
269
|
+
return headers;
|
|
270
|
+
}
|
|
271
|
+
async performAsync(discovery) {
|
|
272
|
+
invariant(discovery.revocationEndpoint, 'Cannot invoke `performAsync()` without a valid revocationEndpoint');
|
|
273
|
+
await requestAsync(discovery.revocationEndpoint, {
|
|
274
|
+
method: 'POST',
|
|
275
|
+
headers: this.getHeaders(),
|
|
276
|
+
body: this.getQueryBody(),
|
|
277
|
+
});
|
|
278
|
+
return true;
|
|
279
|
+
}
|
|
280
|
+
getRequestConfig() {
|
|
281
|
+
return {
|
|
282
|
+
clientId: this.clientId,
|
|
283
|
+
clientSecret: this.clientSecret,
|
|
284
|
+
token: this.token,
|
|
285
|
+
tokenTypeHint: this.tokenTypeHint,
|
|
286
|
+
extraHeaders: this.extraHeaders,
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
getQueryBody() {
|
|
290
|
+
const queryBody = { token: this.token };
|
|
291
|
+
if (this.tokenTypeHint) {
|
|
292
|
+
queryBody.token_type_hint = this.tokenTypeHint;
|
|
293
|
+
}
|
|
294
|
+
if (this.clientId) {
|
|
295
|
+
queryBody.client_id = this.clientId;
|
|
296
|
+
}
|
|
297
|
+
if (this.clientSecret) {
|
|
298
|
+
queryBody.client_secret = this.clientSecret;
|
|
299
|
+
}
|
|
300
|
+
return queryBody;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
/** Exchange an authorization code for an access token. */
|
|
304
|
+
export function exchangeCodeAsync(config, discovery) {
|
|
305
|
+
return new AccessTokenRequest(config).performAsync(discovery);
|
|
306
|
+
}
|
|
307
|
+
/** Refresh an access token. See `TokenResponse.isTokenFresh()`/`shouldRefresh()`. */
|
|
308
|
+
export function refreshAsync(config, discovery) {
|
|
309
|
+
return new RefreshTokenRequest(config).performAsync(discovery);
|
|
310
|
+
}
|
|
311
|
+
/** Revoke a token, effectively requiring the user to sign in again. */
|
|
312
|
+
export function revokeAsync(config, discovery) {
|
|
313
|
+
return new RevokeTokenRequest(config).performAsync(discovery);
|
|
314
|
+
}
|
|
315
|
+
/** Fetch generic user info from the provider's OpenID Connect `userInfoEndpoint`, if supported. */
|
|
316
|
+
export function fetchUserInfoAsync(config, discovery) {
|
|
317
|
+
if (!discovery.userInfoEndpoint) {
|
|
318
|
+
throw new Error('User info endpoint is not defined in the service config discovery document');
|
|
319
|
+
}
|
|
320
|
+
return requestAsync(discovery.userInfoEndpoint, {
|
|
321
|
+
headers: {
|
|
322
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
323
|
+
Authorization: `Bearer ${config.accessToken}`,
|
|
324
|
+
},
|
|
325
|
+
dataType: 'json',
|
|
326
|
+
method: 'GET',
|
|
327
|
+
});
|
|
328
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/** https://tools.ietf.org/html/rfc6749#section-7.1 */
|
|
2
|
+
export type ITokenType = 'bearer' | 'mac';
|
|
3
|
+
/** A hint about the type of the token submitted for revocation. */
|
|
4
|
+
export declare enum TokenTypeHint {
|
|
5
|
+
AccessToken = "access_token",
|
|
6
|
+
RefreshToken = "refresh_token"
|
|
7
|
+
}
|
|
8
|
+
export type ITokenRequestConfig = {
|
|
9
|
+
clientId: string;
|
|
10
|
+
clientSecret?: string;
|
|
11
|
+
extraParams?: Record<string, string>;
|
|
12
|
+
extraHeaders?: Record<string, string>;
|
|
13
|
+
scopes?: string[];
|
|
14
|
+
};
|
|
15
|
+
export type IAccessTokenRequestConfig = ITokenRequestConfig & {
|
|
16
|
+
code: string;
|
|
17
|
+
/** Must match the `redirectUri` used in the `AuthRequest`. */
|
|
18
|
+
redirectUri: string;
|
|
19
|
+
};
|
|
20
|
+
export type IRefreshTokenRequestConfig = ITokenRequestConfig & {
|
|
21
|
+
refreshToken?: string;
|
|
22
|
+
};
|
|
23
|
+
export type IRevokeTokenRequestConfig = Partial<ITokenRequestConfig> & {
|
|
24
|
+
token: string;
|
|
25
|
+
tokenTypeHint?: TokenTypeHint;
|
|
26
|
+
};
|
|
27
|
+
/** https://tools.ietf.org/html/rfc6749#appendix-A.10 */
|
|
28
|
+
export declare enum GrantType {
|
|
29
|
+
AuthorizationCode = "authorization_code",
|
|
30
|
+
Implicit = "implicit",
|
|
31
|
+
RefreshToken = "refresh_token",
|
|
32
|
+
ClientCredentials = "client_credentials"
|
|
33
|
+
}
|
|
34
|
+
export type IServerTokenResponseConfig = {
|
|
35
|
+
access_token: string;
|
|
36
|
+
token_type?: ITokenType;
|
|
37
|
+
expires_in?: number;
|
|
38
|
+
refresh_token?: string;
|
|
39
|
+
scope?: string;
|
|
40
|
+
id_token?: string;
|
|
41
|
+
issued_at?: number;
|
|
42
|
+
};
|
|
43
|
+
export type ITokenResponseConfig = {
|
|
44
|
+
accessToken: string;
|
|
45
|
+
tokenType?: ITokenType;
|
|
46
|
+
expiresIn?: number;
|
|
47
|
+
refreshToken?: string;
|
|
48
|
+
scope?: string;
|
|
49
|
+
state?: string;
|
|
50
|
+
idToken?: string;
|
|
51
|
+
issuedAt?: number;
|
|
52
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** A hint about the type of the token submitted for revocation. */
|
|
2
|
+
export var TokenTypeHint;
|
|
3
|
+
(function (TokenTypeHint) {
|
|
4
|
+
TokenTypeHint["AccessToken"] = "access_token";
|
|
5
|
+
TokenTypeHint["RefreshToken"] = "refresh_token";
|
|
6
|
+
})(TokenTypeHint || (TokenTypeHint = {}));
|
|
7
|
+
/** https://tools.ietf.org/html/rfc6749#appendix-A.10 */
|
|
8
|
+
export var GrantType;
|
|
9
|
+
(function (GrantType) {
|
|
10
|
+
GrantType["AuthorizationCode"] = "authorization_code";
|
|
11
|
+
GrantType["Implicit"] = "implicit";
|
|
12
|
+
GrantType["RefreshToken"] = "refresh_token";
|
|
13
|
+
GrantType["ClientCredentials"] = "client_credentials";
|
|
14
|
+
})(GrantType || (GrantType = {}));
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export * from '../core';
|
|
2
|
+
export { useAuthRequest, useAuthRequestResult, useAutoDiscovery, useFacebookAuthRequest, useGoogleAuthRequest, useGoogleIdTokenAuthRequest, useLoadedAuthRequest, } from './use-auth-request';
|
|
3
|
+
export type { IUseAuthRequestResult } from './use-auth-request';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AuthRequest, FacebookAuthRequest, GoogleAuthRequest } from '../core';
|
|
2
|
+
import type { IAuthRequestClass, IAuthRequestConfig, IAuthRequestPromptOptions, IAuthSessionRedirectUriOptions, IAuthSessionResult, IDiscoveryDocument, IFacebookAuthRequestConfig, IGoogleAuthRequestConfig, IIssuerOrDiscovery, IPromptMethod } from '../core';
|
|
3
|
+
type IDiscoveryValue = IDiscoveryDocument | null;
|
|
4
|
+
type IResultValue = IAuthSessionResult | null;
|
|
5
|
+
export type IUseAuthRequestResult<TRequest extends AuthRequest = AuthRequest> = readonly [TRequest | null, IResultValue, IPromptMethod];
|
|
6
|
+
/** React twin of `useAutoDiscovery`, `null` until the discovery document has loaded */
|
|
7
|
+
export declare function useAutoDiscovery(issuerOrDiscovery: IIssuerOrDiscovery): IDiscoveryValue;
|
|
8
|
+
/** React twin of `useLoadedAuthRequest`, `null` until the request url has loaded */
|
|
9
|
+
export declare function useLoadedAuthRequest(config: IAuthRequestConfig, discovery: IDiscoveryValue, RequestClass: IAuthRequestClass<AuthRequest>): AuthRequest | null;
|
|
10
|
+
/** React twin of `useAuthRequestResult`, the result and the prompt method */
|
|
11
|
+
export declare function useAuthRequestResult(request: AuthRequest | null, discovery: IDiscoveryValue, customOptions?: IAuthRequestPromptOptions): readonly [IResultValue, IPromptMethod];
|
|
12
|
+
/** React twin of `useAuthRequest`: the loaded request, the result and the prompt method */
|
|
13
|
+
export declare function useAuthRequest(config: IAuthRequestConfig, discovery: IDiscoveryValue): IUseAuthRequestResult;
|
|
14
|
+
/** React twin of Google's `useAuthRequest`, exchanges the code for a token by default */
|
|
15
|
+
export declare function useGoogleAuthRequest(config?: Partial<IGoogleAuthRequestConfig>, redirectUriOptions?: Partial<IAuthSessionRedirectUriOptions>): IUseAuthRequestResult<GoogleAuthRequest>;
|
|
16
|
+
/** React twin of Google's `useIdTokenAuthRequest`, the id token is in `params.id_token` */
|
|
17
|
+
export declare function useGoogleIdTokenAuthRequest(config: Partial<IGoogleAuthRequestConfig>, redirectUriOptions?: Partial<IAuthSessionRedirectUriOptions>): IUseAuthRequestResult<GoogleAuthRequest>;
|
|
18
|
+
/** React twin of Facebook's `useAuthRequest` */
|
|
19
|
+
export declare function useFacebookAuthRequest(config?: Partial<IFacebookAuthRequestConfig>, redirectUriOptions?: Partial<IAuthSessionRedirectUriOptions>): IUseAuthRequestResult<FacebookAuthRequest>;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// React twins of `expo-auth-session`'s auth request hooks. The load, prompt and code-exchange
|
|
2
|
+
// logic is the shared controllers in `core/`, React only supplies the lifecycle
|
|
3
|
+
import { createEventValueHook, createResourceHook, } from '@symbiote-native/react';
|
|
4
|
+
import { AUTH_CELL_CHANGE, AuthRequest, FacebookAuthRequest, GoogleAuthRequest, createAutoDiscoveryController, createGoogleExchangeController, createLoadedRequestController, createRequestResultController, facebookDiscovery, googleDiscovery, resolveFacebookRequestSetup, resolveGoogleRequestSetup, toGoogleIdTokenConfig, } from '../core/index.js';
|
|
5
|
+
function readAuthCell(cell) {
|
|
6
|
+
return cell.getSnapshot();
|
|
7
|
+
}
|
|
8
|
+
const useDiscoveryCell = createResourceHook(createAutoDiscoveryController);
|
|
9
|
+
const useLoadedCell = createResourceHook(() => createLoadedRequestController());
|
|
10
|
+
const useResultHolder = createResourceHook(createRequestResultController);
|
|
11
|
+
const useExchangeCell = createResourceHook(createGoogleExchangeController);
|
|
12
|
+
const useDiscoveryValue = createEventValueHook(AUTH_CELL_CHANGE, readAuthCell);
|
|
13
|
+
const useRequestValue = createEventValueHook(AUTH_CELL_CHANGE, readAuthCell);
|
|
14
|
+
const useResultValue = createEventValueHook(AUTH_CELL_CHANGE, readAuthCell);
|
|
15
|
+
/** React twin of `useAutoDiscovery`, `null` until the discovery document has loaded */
|
|
16
|
+
export function useAutoDiscovery(issuerOrDiscovery) {
|
|
17
|
+
return useDiscoveryValue(useDiscoveryCell(issuerOrDiscovery));
|
|
18
|
+
}
|
|
19
|
+
/** React twin of `useLoadedAuthRequest`, `null` until the request url has loaded */
|
|
20
|
+
export function useLoadedAuthRequest(config, discovery, RequestClass) {
|
|
21
|
+
return useRequestValue(useLoadedCell(config, discovery, RequestClass));
|
|
22
|
+
}
|
|
23
|
+
/** React twin of `useAuthRequestResult`, the result and the prompt method */
|
|
24
|
+
export function useAuthRequestResult(request, discovery, customOptions = {}) {
|
|
25
|
+
const holder = useResultHolder(request, discovery, customOptions);
|
|
26
|
+
return [useResultValue(holder.result), holder.promptAsync];
|
|
27
|
+
}
|
|
28
|
+
/** React twin of `useAuthRequest`: the loaded request, the result and the prompt method */
|
|
29
|
+
export function useAuthRequest(config, discovery) {
|
|
30
|
+
const request = useLoadedAuthRequest(config, discovery, AuthRequest);
|
|
31
|
+
const [result, promptAsync] = useAuthRequestResult(request, discovery);
|
|
32
|
+
return [request, result, promptAsync];
|
|
33
|
+
}
|
|
34
|
+
/** React twin of Google's `useAuthRequest`, exchanges the code for a token by default */
|
|
35
|
+
export function useGoogleAuthRequest(config = {}, redirectUriOptions = {}) {
|
|
36
|
+
const { requestConfig, exchange } = resolveGoogleRequestSetup(config, redirectUriOptions);
|
|
37
|
+
const request = useLoadedAuthRequest(requestConfig, googleDiscovery, GoogleAuthRequest);
|
|
38
|
+
const [result, promptAsync] = useAuthRequestResult(request, googleDiscovery);
|
|
39
|
+
const fullResult = useResultValue(useExchangeCell(result, request, exchange));
|
|
40
|
+
return [request, fullResult, promptAsync];
|
|
41
|
+
}
|
|
42
|
+
/** React twin of Google's `useIdTokenAuthRequest`, the id token is in `params.id_token` */
|
|
43
|
+
export function useGoogleIdTokenAuthRequest(config, redirectUriOptions = {}) {
|
|
44
|
+
return useGoogleAuthRequest(toGoogleIdTokenConfig(config), redirectUriOptions);
|
|
45
|
+
}
|
|
46
|
+
/** React twin of Facebook's `useAuthRequest` */
|
|
47
|
+
export function useFacebookAuthRequest(config = {}, redirectUriOptions = {}) {
|
|
48
|
+
const requestConfig = resolveFacebookRequestSetup(config, redirectUriOptions);
|
|
49
|
+
const request = useLoadedAuthRequest(requestConfig, facebookDiscovery, FacebookAuthRequest);
|
|
50
|
+
const [result, promptAsync] = useAuthRequestResult(request, facebookDiscovery);
|
|
51
|
+
return [request, result, promptAsync];
|
|
52
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const useAuthRequest: (config: () => import(".").IAuthRequestConfig, discovery: () => import(".").IDiscoveryDocument | null) => readonly [() => import(".").AuthRequest | null, () => import(".").IAuthSessionResult | null, import(".").IPromptMethod], useAuthRequestResult: (request: () => import(".").AuthRequest | null, discovery: () => import(".").IDiscoveryDocument | null, customOptions?: (() => import("@symbiote-native/web-browser").IWebBrowserOpenOptions & {
|
|
2
|
+
preferEphemeralSession?: boolean;
|
|
3
|
+
preferUniversalLinks?: boolean;
|
|
4
|
+
} & {
|
|
5
|
+
url?: string;
|
|
6
|
+
}) | undefined) => readonly [() => import(".").IAuthSessionResult | null, import(".").IPromptMethod], useAutoDiscovery: (issuerOrDiscovery: () => import(".").IIssuerOrDiscovery) => () => import(".").IDiscoveryDocument | null, useFacebookAuthRequest: (config?: (() => Partial<import(".").IFacebookAuthRequestConfig>) | undefined, redirectUriOptions?: (() => Partial<import(".").IAuthSessionRedirectUriOptions>) | undefined) => readonly [() => import(".").FacebookAuthRequest | null, () => import(".").IAuthSessionResult | null, import(".").IPromptMethod], useGoogleAuthRequest: (config?: (() => Partial<import(".").IGoogleAuthRequestConfig>) | undefined, redirectUriOptions?: (() => Partial<import(".").IAuthSessionRedirectUriOptions>) | undefined) => readonly [() => import(".").GoogleAuthRequest | null, () => import(".").IAuthSessionResult | null, import(".").IPromptMethod], useGoogleIdTokenAuthRequest: (config: () => Partial<import(".").IGoogleAuthRequestConfig>, redirectUriOptions?: (() => Partial<import(".").IAuthSessionRedirectUriOptions>) | undefined) => readonly [() => import(".").GoogleAuthRequest | null, () => import(".").IAuthSessionResult | null, import(".").IPromptMethod], useLoadedAuthRequest: (config: () => import(".").IAuthRequestConfig, discovery: () => import(".").IDiscoveryDocument | null, RequestClass: import(".").IAuthRequestClass<import(".").AuthRequest>) => () => import(".").AuthRequest | null;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Solid twins of `expo-auth-session`'s auth request hooks: accessor arguments, accessor results
|
|
2
|
+
import { createEventValueHook, createResourceHook, } from '@symbiote-native/solid';
|
|
3
|
+
import { GETTER_ARGS, createAuthRequestHooks } from '../core/index.js';
|
|
4
|
+
export const { useAuthRequest, useAuthRequestResult, useAutoDiscovery, useFacebookAuthRequest, useGoogleAuthRequest, useGoogleIdTokenAuthRequest, useLoadedAuthRequest, } = createAuthRequestHooks({
|
|
5
|
+
createResourceHook,
|
|
6
|
+
createEventValueHook,
|
|
7
|
+
readResource: box => box(),
|
|
8
|
+
readValue: box => box(),
|
|
9
|
+
...GETTER_ARGS,
|
|
10
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export declare const useAuthRequest: (config: () => import(".").IAuthRequestConfig, discovery: () => import(".").IDiscoveryDocument | null) => readonly [{
|
|
2
|
+
readonly current: import(".").AuthRequest | null;
|
|
3
|
+
}, {
|
|
4
|
+
readonly current: import(".").IAuthSessionResult | null;
|
|
5
|
+
}, import(".").IPromptMethod], useAuthRequestResult: (request: () => import(".").AuthRequest | null, discovery: () => import(".").IDiscoveryDocument | null, customOptions?: (() => import("@symbiote-native/web-browser").IWebBrowserOpenOptions & {
|
|
6
|
+
preferEphemeralSession?: boolean;
|
|
7
|
+
preferUniversalLinks?: boolean;
|
|
8
|
+
} & {
|
|
9
|
+
url?: string;
|
|
10
|
+
}) | undefined) => readonly [{
|
|
11
|
+
readonly current: import(".").IAuthSessionResult | null;
|
|
12
|
+
}, import(".").IPromptMethod], useAutoDiscovery: (issuerOrDiscovery: () => import(".").IIssuerOrDiscovery) => {
|
|
13
|
+
readonly current: import(".").IDiscoveryDocument | null;
|
|
14
|
+
}, useFacebookAuthRequest: (config?: (() => Partial<import(".").IFacebookAuthRequestConfig>) | undefined, redirectUriOptions?: (() => Partial<import(".").IAuthSessionRedirectUriOptions>) | undefined) => readonly [{
|
|
15
|
+
readonly current: import(".").FacebookAuthRequest | null;
|
|
16
|
+
}, {
|
|
17
|
+
readonly current: import(".").IAuthSessionResult | null;
|
|
18
|
+
}, import(".").IPromptMethod], useGoogleAuthRequest: (config?: (() => Partial<import(".").IGoogleAuthRequestConfig>) | undefined, redirectUriOptions?: (() => Partial<import(".").IAuthSessionRedirectUriOptions>) | undefined) => readonly [{
|
|
19
|
+
readonly current: import(".").GoogleAuthRequest | null;
|
|
20
|
+
}, {
|
|
21
|
+
readonly current: import(".").IAuthSessionResult | null;
|
|
22
|
+
}, import(".").IPromptMethod], useGoogleIdTokenAuthRequest: (config: () => Partial<import(".").IGoogleAuthRequestConfig>, redirectUriOptions?: (() => Partial<import(".").IAuthSessionRedirectUriOptions>) | undefined) => readonly [{
|
|
23
|
+
readonly current: import(".").GoogleAuthRequest | null;
|
|
24
|
+
}, {
|
|
25
|
+
readonly current: import(".").IAuthSessionResult | null;
|
|
26
|
+
}, import(".").IPromptMethod], useLoadedAuthRequest: (config: () => import(".").IAuthRequestConfig, discovery: () => import(".").IDiscoveryDocument | null, RequestClass: import(".").IAuthRequestClass<import(".").AuthRequest>) => {
|
|
27
|
+
readonly current: import(".").AuthRequest | null;
|
|
28
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Svelte twins of `expo-auth-session`'s auth request hooks: getter arguments, boxed getter results
|
|
2
|
+
import { createEventValueHook } from '@symbiote-native/svelte/runes/create-event-value-hook';
|
|
3
|
+
import { createResourceHook } from '@symbiote-native/svelte/runes/create-resource-hook';
|
|
4
|
+
import { GETTER_ARGS, createAuthRequestHooks } from '../core/index.js';
|
|
5
|
+
export const { useAuthRequest, useAuthRequestResult, useAutoDiscovery, useFacebookAuthRequest, useGoogleAuthRequest, useGoogleIdTokenAuthRequest, useLoadedAuthRequest, } = createAuthRequestHooks({
|
|
6
|
+
createResourceHook,
|
|
7
|
+
createEventValueHook,
|
|
8
|
+
readResource: box => box.current,
|
|
9
|
+
readValue: box => box.current,
|
|
10
|
+
...GETTER_ARGS,
|
|
11
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { MaybeRefOrGetter, ShallowRef } from '@vue/runtime-core';
|
|
2
|
+
export declare const useAuthRequest: (config: MaybeRefOrGetter<import(".").IAuthRequestConfig>, discovery: MaybeRefOrGetter<import(".").IDiscoveryDocument | null>) => readonly [ShallowRef<import(".").AuthRequest | null>, ShallowRef<import(".").IAuthSessionResult | null>, import(".").IPromptMethod], useAuthRequestResult: (request: MaybeRefOrGetter<import(".").AuthRequest | null>, discovery: MaybeRefOrGetter<import(".").IDiscoveryDocument | null>, customOptions?: MaybeRefOrGetter<import("@symbiote-native/web-browser").IWebBrowserOpenOptions & {
|
|
3
|
+
preferEphemeralSession?: boolean;
|
|
4
|
+
preferUniversalLinks?: boolean;
|
|
5
|
+
} & {
|
|
6
|
+
url?: string;
|
|
7
|
+
}> | undefined) => readonly [ShallowRef<import(".").IAuthSessionResult | null>, import(".").IPromptMethod], useAutoDiscovery: (issuerOrDiscovery: MaybeRefOrGetter<import(".").IIssuerOrDiscovery>) => ShallowRef<import(".").IDiscoveryDocument | null>, useFacebookAuthRequest: (config?: MaybeRefOrGetter<Partial<import(".").IFacebookAuthRequestConfig>> | undefined, redirectUriOptions?: MaybeRefOrGetter<Partial<import(".").IAuthSessionRedirectUriOptions>> | undefined) => readonly [ShallowRef<import(".").FacebookAuthRequest | null>, ShallowRef<import(".").IAuthSessionResult | null>, import(".").IPromptMethod], useGoogleAuthRequest: (config?: MaybeRefOrGetter<Partial<import(".").IGoogleAuthRequestConfig>> | undefined, redirectUriOptions?: MaybeRefOrGetter<Partial<import(".").IAuthSessionRedirectUriOptions>> | undefined) => readonly [ShallowRef<import(".").GoogleAuthRequest | null>, ShallowRef<import(".").IAuthSessionResult | null>, import(".").IPromptMethod], useGoogleIdTokenAuthRequest: (config: MaybeRefOrGetter<Partial<import(".").IGoogleAuthRequestConfig>>, redirectUriOptions?: MaybeRefOrGetter<Partial<import(".").IAuthSessionRedirectUriOptions>> | undefined) => readonly [ShallowRef<import(".").GoogleAuthRequest | null>, ShallowRef<import(".").IAuthSessionResult | null>, import(".").IPromptMethod], useLoadedAuthRequest: (config: MaybeRefOrGetter<import(".").IAuthRequestConfig>, discovery: MaybeRefOrGetter<import(".").IDiscoveryDocument | null>, RequestClass: import(".").IAuthRequestClass<import(".").AuthRequest>) => ShallowRef<import(".").AuthRequest | null>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Vue twins of `expo-auth-session`'s auth request hooks: ref or getter arguments, ref results
|
|
2
|
+
import { toValue } from '@vue/runtime-core';
|
|
3
|
+
import { createEventValueHook, createResourceHook } from '@symbiote-native/vue';
|
|
4
|
+
import { createAuthRequestHooks } from '../core/index.js';
|
|
5
|
+
export const { useAuthRequest, useAuthRequestResult, useAutoDiscovery, useFacebookAuthRequest, useGoogleAuthRequest, useGoogleIdTokenAuthRequest, useLoadedAuthRequest, } = createAuthRequestHooks({
|
|
6
|
+
createResourceHook,
|
|
7
|
+
createEventValueHook,
|
|
8
|
+
readResource: box => box.value,
|
|
9
|
+
readValue: box => box.value,
|
|
10
|
+
toGetter: arg => () => toValue(arg),
|
|
11
|
+
constant: value => value,
|
|
12
|
+
});
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// The hooks are the `inject*` twins below, the rest is the shared core with nothing to wrap
|
|
2
|
+
export * from '../core';
|
|
3
|
+
export { injectAuthRequest, injectAuthRequestResult, injectAutoDiscovery, injectFacebookAuthRequest, injectGoogleAuthRequest, injectGoogleIdTokenAuthRequest, injectLoadedAuthRequest, } from './use-auth-request';
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/angular/index.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,cAAc,SAAS,CAAC;AACxB,OAAO,EACL,iBAAiB,EACjB,uBAAuB,EACvB,mBAAmB,EACnB,yBAAyB,EACzB,uBAAuB,EACvB,8BAA8B,EAC9B,uBAAuB,GACxB,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Signal } from '@angular/core';
|
|
2
|
+
export declare const injectAuthRequest: (config: () => import(".").IAuthRequestConfig, discovery: () => import(".").IDiscoveryDocument | null) => readonly [Signal<import(".").AuthRequest | null>, Signal<import(".").IAuthSessionResult | null>, import(".").IPromptMethod], injectAuthRequestResult: (request: () => import(".").AuthRequest | null, discovery: () => import(".").IDiscoveryDocument | null, customOptions?: (() => import("@symbiote-native/web-browser").IWebBrowserOpenOptions & {
|
|
3
|
+
preferEphemeralSession?: boolean;
|
|
4
|
+
preferUniversalLinks?: boolean;
|
|
5
|
+
} & {
|
|
6
|
+
url?: string;
|
|
7
|
+
}) | undefined) => readonly [Signal<import(".").IAuthSessionResult | null>, import(".").IPromptMethod], injectAutoDiscovery: (issuerOrDiscovery: () => import(".").IIssuerOrDiscovery) => Signal<import(".").IDiscoveryDocument | null>, injectFacebookAuthRequest: (config?: (() => Partial<import(".").IFacebookAuthRequestConfig>) | undefined, redirectUriOptions?: (() => Partial<import(".").IAuthSessionRedirectUriOptions>) | undefined) => readonly [Signal<import(".").FacebookAuthRequest | null>, Signal<import(".").IAuthSessionResult | null>, import(".").IPromptMethod], injectGoogleAuthRequest: (config?: (() => Partial<import(".").IGoogleAuthRequestConfig>) | undefined, redirectUriOptions?: (() => Partial<import(".").IAuthSessionRedirectUriOptions>) | undefined) => readonly [Signal<import(".").GoogleAuthRequest | null>, Signal<import(".").IAuthSessionResult | null>, import(".").IPromptMethod], injectGoogleIdTokenAuthRequest: (config: () => Partial<import(".").IGoogleAuthRequestConfig>, redirectUriOptions?: (() => Partial<import(".").IAuthSessionRedirectUriOptions>) | undefined) => readonly [Signal<import(".").GoogleAuthRequest | null>, Signal<import(".").IAuthSessionResult | null>, import(".").IPromptMethod], injectLoadedAuthRequest: (config: () => import(".").IAuthRequestConfig, discovery: () => import(".").IDiscoveryDocument | null, RequestClass: import(".").IAuthRequestClass<import(".").AuthRequest>) => Signal<import(".").AuthRequest | null>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Angular twins of `expo-auth-session`'s auth request hooks, `injectX` shape, call them in an
|
|
2
|
+
// injection context: getter or signal arguments, signal results
|
|
3
|
+
import { createEventValueHook, createResourceHook, } from '@symbiote-native/angular';
|
|
4
|
+
import { GETTER_ARGS, createAuthRequestHooks } from '../core';
|
|
5
|
+
export const { useAuthRequest: injectAuthRequest, useAuthRequestResult: injectAuthRequestResult, useAutoDiscovery: injectAutoDiscovery, useFacebookAuthRequest: injectFacebookAuthRequest, useGoogleAuthRequest: injectGoogleAuthRequest, useGoogleIdTokenAuthRequest: injectGoogleIdTokenAuthRequest, useLoadedAuthRequest: injectLoadedAuthRequest, } = createAuthRequestHooks({
|
|
6
|
+
createResourceHook,
|
|
7
|
+
createEventValueHook,
|
|
8
|
+
readResource: box => box(),
|
|
9
|
+
readValue: box => box(),
|
|
10
|
+
...GETTER_ARGS,
|
|
11
|
+
});
|
|
12
|
+
//# sourceMappingURL=use-auth-request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-auth-request.js","sourceRoot":"","sources":["../../src/angular/use-auth-request.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,gEAAgE;AAGhE,OAAO,EACL,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAO9D,MAAM,CAAC,MAAM,EACX,cAAc,EAAE,iBAAiB,EACjC,oBAAoB,EAAE,uBAAuB,EAC7C,gBAAgB,EAAE,mBAAmB,EACrC,sBAAsB,EAAE,yBAAyB,EACjD,oBAAoB,EAAE,uBAAuB,EAC7C,2BAA2B,EAAE,8BAA8B,EAC3D,oBAAoB,EAAE,uBAAuB,GAC9C,GAAG,sBAAsB,CAAwC;IAChE,kBAAkB;IAClB,oBAAoB;IACpB,YAAY,EAAE,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE;IAC1B,SAAS,EAAE,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE;IACvB,GAAG,WAAW;CACf,CAAC,CAAC"}
|