@usync/oauth2 0.0.6 → 0.1.1
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/dist/index.js +135 -143
- package/package.json +1 -1
- package/dist/common.d.ts +0 -7
- package/dist/index.d.ts +0 -7
- package/dist/providers/base.d.ts +0 -20
- package/dist/providers/dropbox.d.ts +0 -13
- package/dist/providers/google.d.ts +0 -18
- package/dist/providers/index.d.ts +0 -10
- package/dist/providers/microsoft.d.ts +0 -15
- package/dist/types.d.ts +0 -18
- package/dist/util.d.ts +0 -13
package/dist/index.js
CHANGED
|
@@ -1,43 +1,32 @@
|
|
|
1
|
-
import { nanoid as
|
|
2
|
-
const R = 1,
|
|
3
|
-
class
|
|
4
|
-
constructor(e,
|
|
5
|
-
super(
|
|
1
|
+
import { nanoid as U } from "nanoid";
|
|
2
|
+
const R = 1, a = 2, d = 3;
|
|
3
|
+
class i extends Error {
|
|
4
|
+
constructor(e, s) {
|
|
5
|
+
super(s || `OAuth2Error: code=${e}`), this.code = e;
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
let s = "", o = 0;
|
|
14
|
-
for (; o < i.length; ) {
|
|
15
|
-
let t = i[o++], c = i[o++], a = i[o++];
|
|
16
|
-
if (s += e[t >> 2], s += e[(t & 3) << 4 | (c || 0) >> 4], c == null || (s += e[(c & 15) << 2 | (a || 0) >> 6]), a == null)
|
|
17
|
-
break;
|
|
18
|
-
s += e[a & 63];
|
|
19
|
-
}
|
|
20
|
-
return s;
|
|
21
|
-
}
|
|
22
|
-
function O(i) {
|
|
23
|
-
return b(i, S(), !1);
|
|
8
|
+
function O(r) {
|
|
9
|
+
let e = "";
|
|
10
|
+
for (const s of r)
|
|
11
|
+
e += String.fromCharCode(s);
|
|
12
|
+
return btoa(e).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
24
13
|
}
|
|
25
14
|
function _() {
|
|
26
|
-
return
|
|
15
|
+
return U(8);
|
|
27
16
|
}
|
|
28
17
|
function k() {
|
|
29
|
-
return
|
|
18
|
+
return U(64);
|
|
30
19
|
}
|
|
31
|
-
async function u(
|
|
32
|
-
const e = "S256",
|
|
20
|
+
async function u(r) {
|
|
21
|
+
const e = "S256", s = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(r));
|
|
33
22
|
return {
|
|
34
|
-
codeChallenge: O(new Uint8Array(
|
|
23
|
+
codeChallenge: O(new Uint8Array(s)),
|
|
35
24
|
codeChallengeMethod: e
|
|
36
25
|
};
|
|
37
26
|
}
|
|
38
27
|
class w {
|
|
39
|
-
constructor(e,
|
|
40
|
-
this.options = e, this._accessToken = null, this._refreshToken = null,
|
|
28
|
+
constructor(e, s) {
|
|
29
|
+
this.options = e, this._accessToken = null, this._refreshToken = null, s && (this.setRefreshToken(s.refreshToken), this.setAccessToken(s.accessToken), this.session = s.session);
|
|
41
30
|
}
|
|
42
31
|
_getValidToken(e) {
|
|
43
32
|
return e && (!e.expiresAt || Date.now() < e.expiresAt) ? e.token : void 0;
|
|
@@ -49,14 +38,14 @@ class w {
|
|
|
49
38
|
this.setRefreshToken(e), this.options.onSetRefreshToken?.(e);
|
|
50
39
|
}
|
|
51
40
|
getAccessToken() {
|
|
52
|
-
if (!this._accessToken) throw new
|
|
41
|
+
if (!this._accessToken) throw new i(d);
|
|
53
42
|
const e = this._getValidToken(this._accessToken);
|
|
54
|
-
if (!e) throw new
|
|
43
|
+
if (!e) throw new i(R);
|
|
55
44
|
return e;
|
|
56
45
|
}
|
|
57
46
|
getRefreshToken() {
|
|
58
47
|
const e = this._getValidToken(this._refreshToken);
|
|
59
|
-
if (!e) throw new
|
|
48
|
+
if (!e) throw new i(d, "Invalid refresh token");
|
|
60
49
|
return e;
|
|
61
50
|
}
|
|
62
51
|
setAccessToken(e) {
|
|
@@ -66,51 +55,51 @@ class w {
|
|
|
66
55
|
this._refreshToken = e ?? null;
|
|
67
56
|
}
|
|
68
57
|
}
|
|
69
|
-
const
|
|
58
|
+
const b = "https://www.dropbox.com/oauth2/authorize", A = "https://api.dropbox.com/oauth2/token", T = class T extends w {
|
|
70
59
|
async buildAuthUrl() {
|
|
71
60
|
this.session = {
|
|
72
61
|
state: _(),
|
|
73
62
|
codeVerifier: k()
|
|
74
63
|
};
|
|
75
|
-
const { codeChallenge: e, codeChallengeMethod:
|
|
64
|
+
const { codeChallenge: e, codeChallengeMethod: s } = await u(
|
|
76
65
|
this.session.codeVerifier
|
|
77
|
-
),
|
|
66
|
+
), o = new URL(b);
|
|
78
67
|
return Object.entries({
|
|
79
68
|
client_id: this.options.clientId,
|
|
80
69
|
code_challenge: e,
|
|
81
|
-
code_challenge_method:
|
|
70
|
+
code_challenge_method: s,
|
|
82
71
|
redirect_uri: this.options.redirectUrl,
|
|
83
72
|
response_type: "code",
|
|
84
73
|
token_access_type: "offline",
|
|
85
74
|
scope: this.options.scope,
|
|
86
75
|
state: this.session.state
|
|
87
|
-
}).forEach(([
|
|
88
|
-
t &&
|
|
89
|
-
}),
|
|
76
|
+
}).forEach(([n, t]) => {
|
|
77
|
+
t && o.searchParams.set(n, t);
|
|
78
|
+
}), o.href;
|
|
90
79
|
}
|
|
91
80
|
async finishAuth(e) {
|
|
92
81
|
if (!this.session || this.session.state !== e.searchParams.get("state"))
|
|
93
|
-
throw new
|
|
94
|
-
const
|
|
95
|
-
if (!
|
|
96
|
-
const
|
|
82
|
+
throw new i(a, "state doesn't match");
|
|
83
|
+
const s = e.searchParams.get("code");
|
|
84
|
+
if (!s) throw new i(a, "Invalid code");
|
|
85
|
+
const o = new URLSearchParams();
|
|
97
86
|
Object.entries({
|
|
98
87
|
client_id: this.options.clientId,
|
|
99
88
|
client_secret: this.options.clientSecret,
|
|
100
|
-
code:
|
|
89
|
+
code: s,
|
|
101
90
|
code_verifier: this.session.codeVerifier,
|
|
102
91
|
grant_type: "authorization_code",
|
|
103
92
|
redirect_uri: this.options.redirectUrl
|
|
104
|
-
}).forEach(([c,
|
|
105
|
-
|
|
93
|
+
}).forEach(([c, h]) => {
|
|
94
|
+
h != null && o.append(c, h);
|
|
106
95
|
});
|
|
107
|
-
const
|
|
96
|
+
const n = await fetch(A, {
|
|
108
97
|
method: "POST",
|
|
109
|
-
body:
|
|
110
|
-
}), t = await
|
|
111
|
-
if (!
|
|
98
|
+
body: o
|
|
99
|
+
}), t = await n.json();
|
|
100
|
+
if (!n.ok) throw { status: n.status, data: t };
|
|
112
101
|
if (!t.refresh_token)
|
|
113
|
-
throw new
|
|
102
|
+
throw new i(a, "Failed to get refresh_token");
|
|
114
103
|
return this._updateRefreshToken({
|
|
115
104
|
token: t.refresh_token,
|
|
116
105
|
scope: t.scope
|
|
@@ -120,77 +109,77 @@ const g = class g extends w {
|
|
|
120
109
|
}), t.access_token;
|
|
121
110
|
}
|
|
122
111
|
async refreshToken() {
|
|
123
|
-
const e = new URLSearchParams(),
|
|
112
|
+
const e = new URLSearchParams(), s = this.getRefreshToken();
|
|
124
113
|
Object.entries({
|
|
125
114
|
client_id: this.options.clientId,
|
|
126
115
|
client_secret: this.options.clientSecret,
|
|
127
116
|
grant_type: "refresh_token",
|
|
128
|
-
refresh_token:
|
|
117
|
+
refresh_token: s
|
|
129
118
|
}).forEach(([t, c]) => {
|
|
130
|
-
e.append(t, c);
|
|
119
|
+
c != null && e.append(t, c);
|
|
131
120
|
});
|
|
132
|
-
const
|
|
121
|
+
const o = await fetch(A, {
|
|
133
122
|
method: "POST",
|
|
134
123
|
body: e
|
|
135
|
-
}),
|
|
136
|
-
if (!
|
|
124
|
+
}), n = await o.json();
|
|
125
|
+
if (!o.ok) throw { status: o.status, data: n };
|
|
137
126
|
return this._updateAccessToken({
|
|
138
|
-
token:
|
|
139
|
-
expiresAt: Date.now() +
|
|
140
|
-
}),
|
|
127
|
+
token: n.access_token,
|
|
128
|
+
expiresAt: Date.now() + n.expires_in * 1e3
|
|
129
|
+
}), n.access_token;
|
|
141
130
|
}
|
|
142
131
|
};
|
|
143
|
-
|
|
132
|
+
T.Scopes = {
|
|
144
133
|
account: "account_info.read"
|
|
145
134
|
};
|
|
146
|
-
let p =
|
|
147
|
-
const
|
|
135
|
+
let p = T;
|
|
136
|
+
const S = "https://accounts.google.com/o/oauth2/v2/auth", y = "https://oauth2.googleapis.com/token", g = class g extends w {
|
|
148
137
|
async buildAuthUrl() {
|
|
149
138
|
this.session = {
|
|
150
139
|
state: _(),
|
|
151
140
|
codeVerifier: k()
|
|
152
141
|
};
|
|
153
|
-
const { codeChallenge: e, codeChallengeMethod:
|
|
142
|
+
const { codeChallenge: e, codeChallengeMethod: s } = await u(
|
|
154
143
|
this.session.codeVerifier
|
|
155
|
-
),
|
|
144
|
+
), o = new URL(S);
|
|
156
145
|
return Object.entries({
|
|
157
146
|
access_type: "offline",
|
|
158
147
|
client_id: this.options.clientId,
|
|
159
148
|
code_challenge: e,
|
|
160
|
-
code_challenge_method:
|
|
149
|
+
code_challenge_method: s,
|
|
161
150
|
include_granted_scopes: "true",
|
|
162
151
|
prompt: "consent",
|
|
163
152
|
redirect_uri: this.options.redirectUrl,
|
|
164
153
|
response_type: "code",
|
|
165
154
|
scope: this.options.scope,
|
|
166
155
|
state: this.session.state
|
|
167
|
-
}).forEach(([
|
|
168
|
-
t &&
|
|
169
|
-
}),
|
|
156
|
+
}).forEach(([n, t]) => {
|
|
157
|
+
t && o.searchParams.set(n, t);
|
|
158
|
+
}), o.href;
|
|
170
159
|
}
|
|
171
160
|
async finishAuth(e) {
|
|
172
161
|
if (!this.session || this.session.state !== e.searchParams.get("state"))
|
|
173
|
-
throw new
|
|
174
|
-
const
|
|
175
|
-
if (!
|
|
176
|
-
const
|
|
162
|
+
throw new i(a, "state doesn't match");
|
|
163
|
+
const s = e.searchParams.get("code");
|
|
164
|
+
if (!s) throw new i(a, "Invalid code");
|
|
165
|
+
const o = new URLSearchParams();
|
|
177
166
|
Object.entries({
|
|
178
167
|
client_id: this.options.clientId,
|
|
179
168
|
client_secret: this.options.clientSecret,
|
|
180
|
-
code:
|
|
169
|
+
code: s,
|
|
181
170
|
code_verifier: this.session.codeVerifier,
|
|
182
171
|
grant_type: "authorization_code",
|
|
183
172
|
redirect_uri: this.options.redirectUrl
|
|
184
|
-
}).forEach(([c,
|
|
185
|
-
|
|
173
|
+
}).forEach(([c, h]) => {
|
|
174
|
+
h != null && o.append(c, h);
|
|
186
175
|
});
|
|
187
|
-
const
|
|
176
|
+
const n = await fetch(y, {
|
|
188
177
|
method: "POST",
|
|
189
|
-
body:
|
|
190
|
-
}), t = await
|
|
191
|
-
if (!
|
|
178
|
+
body: o
|
|
179
|
+
}), t = await n.json();
|
|
180
|
+
if (!n.ok) throw { status: n.status, data: t };
|
|
192
181
|
if (!t.refresh_token)
|
|
193
|
-
throw new
|
|
182
|
+
throw new i(a, "Failed to get refresh_token");
|
|
194
183
|
return this._updateRefreshToken({
|
|
195
184
|
token: t.refresh_token,
|
|
196
185
|
scope: t.scope
|
|
@@ -200,79 +189,82 @@ const T = class T extends w {
|
|
|
200
189
|
}), t.access_token;
|
|
201
190
|
}
|
|
202
191
|
async refreshToken() {
|
|
203
|
-
const e = new URLSearchParams(),
|
|
192
|
+
const e = new URLSearchParams(), s = this.getRefreshToken();
|
|
204
193
|
Object.entries({
|
|
205
194
|
client_id: this.options.clientId,
|
|
206
195
|
client_secret: this.options.clientSecret,
|
|
207
196
|
grant_type: "refresh_token",
|
|
208
|
-
refresh_token:
|
|
197
|
+
refresh_token: s,
|
|
209
198
|
scope: this.options.scope
|
|
210
199
|
}).forEach(([t, c]) => {
|
|
211
200
|
c != null && e.append(t, c);
|
|
212
201
|
});
|
|
213
|
-
const
|
|
202
|
+
const o = await fetch(y, {
|
|
214
203
|
method: "POST",
|
|
215
204
|
body: e
|
|
216
|
-
}),
|
|
217
|
-
if (!
|
|
205
|
+
}), n = await o.json();
|
|
206
|
+
if (!o.ok) throw { status: o.status, data: n };
|
|
218
207
|
return this._updateAccessToken({
|
|
219
|
-
token:
|
|
220
|
-
expiresAt: Date.now() +
|
|
221
|
-
}),
|
|
208
|
+
token: n.access_token,
|
|
209
|
+
expiresAt: Date.now() + n.expires_in * 1e3
|
|
210
|
+
}), n.access_token;
|
|
222
211
|
}
|
|
223
212
|
};
|
|
224
|
-
|
|
213
|
+
g.Scopes = {
|
|
225
214
|
account: "https://www.googleapis.com/auth/userinfo.profile",
|
|
226
215
|
"drive.appdata": "https://www.googleapis.com/auth/drive.appdata",
|
|
227
216
|
imap: "https://mail.google.com/"
|
|
228
217
|
};
|
|
229
|
-
let
|
|
218
|
+
let l = g;
|
|
230
219
|
const m = class m extends w {
|
|
220
|
+
oauth2Url(e) {
|
|
221
|
+
return `https://login.microsoftonline.com/${this.options.provider?.microsoft?.accountType ?? "common"}/oauth2/v2.0/${e}`;
|
|
222
|
+
}
|
|
231
223
|
async buildAuthUrl() {
|
|
232
224
|
this.session = {
|
|
233
225
|
state: _(),
|
|
234
226
|
codeVerifier: k()
|
|
235
227
|
};
|
|
236
|
-
const { codeChallenge: e, codeChallengeMethod:
|
|
228
|
+
const { codeChallenge: e, codeChallengeMethod: s } = await u(
|
|
237
229
|
this.session.codeVerifier
|
|
238
|
-
),
|
|
230
|
+
), o = new URL(this.oauth2Url("authorize"));
|
|
239
231
|
return Object.entries({
|
|
240
232
|
client_id: this.options.clientId,
|
|
241
233
|
code_challenge: e,
|
|
242
|
-
code_challenge_method:
|
|
234
|
+
code_challenge_method: s,
|
|
243
235
|
redirect_uri: this.options.redirectUrl,
|
|
244
236
|
response_mode: "query",
|
|
245
237
|
response_type: "code",
|
|
246
238
|
scope: this.options.scope,
|
|
247
239
|
state: this.session.state
|
|
248
|
-
}).forEach(([
|
|
249
|
-
t &&
|
|
250
|
-
}),
|
|
240
|
+
}).forEach(([n, t]) => {
|
|
241
|
+
t && o.searchParams.set(n, t);
|
|
242
|
+
}), o.href;
|
|
251
243
|
}
|
|
252
244
|
async finishAuth(e) {
|
|
253
245
|
if (!this.session || this.session.state !== e.searchParams.get("state"))
|
|
254
|
-
throw new
|
|
255
|
-
const
|
|
256
|
-
if (!
|
|
257
|
-
const
|
|
246
|
+
throw new i(a, "state doesn't match");
|
|
247
|
+
const s = e.searchParams.get("code");
|
|
248
|
+
if (!s) throw new i(a, "Invalid code");
|
|
249
|
+
const o = new URLSearchParams();
|
|
258
250
|
Object.entries({
|
|
259
251
|
client_id: this.options.clientId,
|
|
260
252
|
client_secret: this.options.clientSecret,
|
|
261
|
-
code:
|
|
253
|
+
code: s,
|
|
262
254
|
code_verifier: this.session.codeVerifier,
|
|
263
255
|
grant_type: "authorization_code",
|
|
264
256
|
redirect_uri: this.options.redirectUrl,
|
|
265
257
|
scope: this.options.scope
|
|
266
|
-
}).forEach(([c,
|
|
267
|
-
|
|
258
|
+
}).forEach(([c, h]) => {
|
|
259
|
+
h != null && o.append(c, h);
|
|
268
260
|
});
|
|
269
|
-
const
|
|
261
|
+
const n = await fetch(this.oauth2Url("token"), {
|
|
270
262
|
method: "POST",
|
|
271
|
-
body:
|
|
272
|
-
}), t = await
|
|
273
|
-
if (!
|
|
263
|
+
body: o
|
|
264
|
+
}), t = await n.json();
|
|
265
|
+
if (!n.ok) throw { status: n.status, data: t };
|
|
274
266
|
if (!t.refresh_token)
|
|
275
|
-
throw new
|
|
267
|
+
throw new i(a, "Failed to get refresh_token");
|
|
276
268
|
return this._updateRefreshToken({
|
|
277
269
|
token: t.refresh_token,
|
|
278
270
|
scope: t.scope
|
|
@@ -282,25 +274,25 @@ const m = class m extends w {
|
|
|
282
274
|
}), t.access_token;
|
|
283
275
|
}
|
|
284
276
|
async refreshToken() {
|
|
285
|
-
const e = new URLSearchParams(),
|
|
277
|
+
const e = new URLSearchParams(), s = this.getRefreshToken();
|
|
286
278
|
Object.entries({
|
|
287
279
|
client_id: this.options.clientId,
|
|
288
280
|
client_secret: this.options.clientSecret,
|
|
289
281
|
grant_type: "refresh_token",
|
|
290
|
-
refresh_token:
|
|
282
|
+
refresh_token: s,
|
|
291
283
|
scope: this.options.scope
|
|
292
284
|
}).forEach(([t, c]) => {
|
|
293
|
-
c && e.append(t, c);
|
|
285
|
+
c != null && e.append(t, c);
|
|
294
286
|
});
|
|
295
|
-
const
|
|
287
|
+
const o = await fetch(this.oauth2Url("token"), {
|
|
296
288
|
method: "POST",
|
|
297
289
|
body: e
|
|
298
|
-
}),
|
|
299
|
-
if (!
|
|
290
|
+
}), n = await o.json();
|
|
291
|
+
if (!o.ok) throw { status: o.status, data: n };
|
|
300
292
|
return this._updateAccessToken({
|
|
301
|
-
token:
|
|
302
|
-
expiresAt: Date.now() +
|
|
303
|
-
}),
|
|
293
|
+
token: n.access_token,
|
|
294
|
+
expiresAt: Date.now() + n.expires_in * 1e3
|
|
295
|
+
}), n.access_token;
|
|
304
296
|
}
|
|
305
297
|
};
|
|
306
298
|
m.Scopes = {
|
|
@@ -308,49 +300,49 @@ m.Scopes = {
|
|
|
308
300
|
imap: "offline_access https://outlook.office.com/IMAP.AccessAsUser.All",
|
|
309
301
|
onedrive: "openid profile Files.ReadWrite.AppFolder offline_access"
|
|
310
302
|
};
|
|
311
|
-
let
|
|
312
|
-
const
|
|
303
|
+
let f = m;
|
|
304
|
+
const E = {
|
|
313
305
|
dropbox: p,
|
|
314
|
-
google:
|
|
315
|
-
microsoft:
|
|
306
|
+
google: l,
|
|
307
|
+
microsoft: f
|
|
316
308
|
};
|
|
317
|
-
function
|
|
318
|
-
return new
|
|
309
|
+
function x(r, e) {
|
|
310
|
+
return new E[e.provider](r);
|
|
319
311
|
}
|
|
320
|
-
async function
|
|
321
|
-
let
|
|
312
|
+
async function I(r, e) {
|
|
313
|
+
let s;
|
|
322
314
|
try {
|
|
323
|
-
|
|
324
|
-
} catch (
|
|
325
|
-
if (!(
|
|
326
|
-
throw
|
|
327
|
-
switch (
|
|
315
|
+
s = r.getAccessToken();
|
|
316
|
+
} catch (o) {
|
|
317
|
+
if (!(o instanceof i))
|
|
318
|
+
throw o;
|
|
319
|
+
switch (o.code) {
|
|
328
320
|
case d: {
|
|
329
|
-
if (!e) throw
|
|
330
|
-
const
|
|
331
|
-
|
|
321
|
+
if (!e) throw o;
|
|
322
|
+
const n = await r.buildAuthUrl(), t = await e(n);
|
|
323
|
+
s = await r.finishAuth(new URL(t));
|
|
332
324
|
break;
|
|
333
325
|
}
|
|
334
326
|
case R: {
|
|
335
|
-
|
|
327
|
+
s = await r.refreshToken();
|
|
336
328
|
break;
|
|
337
329
|
}
|
|
338
330
|
default:
|
|
339
|
-
throw
|
|
331
|
+
throw o;
|
|
340
332
|
}
|
|
341
333
|
}
|
|
342
|
-
return
|
|
334
|
+
return s;
|
|
343
335
|
}
|
|
344
336
|
export {
|
|
345
337
|
p as DropboxAuthorizer,
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
338
|
+
l as GoogleAuthorizer,
|
|
339
|
+
f as MicrosoftAuthorizer,
|
|
340
|
+
a as OAUTH2_AUTH_ERROR,
|
|
349
341
|
R as OAUTH2_NEED_REFRESH,
|
|
350
342
|
d as OAUTH2_UNAUTHORIZED,
|
|
351
343
|
w as OAuth2Authorizer,
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
344
|
+
E as OAuth2Authorizers,
|
|
345
|
+
i as OAuth2Error,
|
|
346
|
+
I as ensureAccessToken,
|
|
347
|
+
x as getAuthorizer
|
|
356
348
|
};
|
package/package.json
CHANGED
package/dist/common.d.ts
DELETED
package/dist/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { OAuth2Authorizer } from "./providers";
|
|
2
|
-
import type { IOAuth2Account, IOAuth2Options } from "./types";
|
|
3
|
-
export * from "./common";
|
|
4
|
-
export * from "./providers";
|
|
5
|
-
export * from "./types";
|
|
6
|
-
export declare function getAuthorizer(options: IOAuth2Options, auth: IOAuth2Account): import("./providers").DropboxAuthorizer | import("./providers").GoogleAuthorizer | import("./providers").MicrosoftAuthorizer;
|
|
7
|
-
export declare function ensureAccessToken(authorizer: OAuth2Authorizer, handleOAuth2?: (url: string) => Promise<string>): Promise<string>;
|
package/dist/providers/base.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { IOAuth2Options, TokenData } from "../types";
|
|
2
|
-
export declare abstract class OAuth2Authorizer {
|
|
3
|
-
protected options: IOAuth2Options;
|
|
4
|
-
abstract buildAuthUrl(): Promise<string>;
|
|
5
|
-
abstract finishAuth(url: URL): Promise<string>;
|
|
6
|
-
abstract refreshToken(): Promise<string>;
|
|
7
|
-
protected _accessToken: TokenData | null;
|
|
8
|
-
protected _refreshToken: TokenData | null;
|
|
9
|
-
constructor(options: IOAuth2Options, initialData?: {
|
|
10
|
-
accessToken?: TokenData;
|
|
11
|
-
refreshToken?: TokenData;
|
|
12
|
-
});
|
|
13
|
-
protected _getValidToken(value?: TokenData | null): string | undefined;
|
|
14
|
-
protected _updateAccessToken(value: TokenData | null): void;
|
|
15
|
-
protected _updateRefreshToken(value: TokenData | null): void;
|
|
16
|
-
getAccessToken(): string;
|
|
17
|
-
getRefreshToken(): string;
|
|
18
|
-
setAccessToken(value?: TokenData | null): void;
|
|
19
|
-
setRefreshToken(value?: TokenData | null): void;
|
|
20
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { OAuth2Authorizer } from "./base.ts";
|
|
2
|
-
export declare class DropboxAuthorizer extends OAuth2Authorizer {
|
|
3
|
-
private session;
|
|
4
|
-
/**
|
|
5
|
-
* Ref: https://www.dropbox.com/developers/documentation/http/documentation
|
|
6
|
-
*/
|
|
7
|
-
static Scopes: {
|
|
8
|
-
account: string;
|
|
9
|
-
};
|
|
10
|
-
buildAuthUrl(): Promise<string>;
|
|
11
|
-
finishAuth(url: URL): Promise<string>;
|
|
12
|
-
refreshToken(): Promise<string>;
|
|
13
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { OAuth2Authorizer } from "./base.ts";
|
|
2
|
-
/**
|
|
3
|
-
* Ref: https://developers.google.com/identity/protocols/oauth2/web-server
|
|
4
|
-
*/
|
|
5
|
-
export declare class GoogleAuthorizer extends OAuth2Authorizer {
|
|
6
|
-
private session;
|
|
7
|
-
/**
|
|
8
|
-
* Ref: https://developers.google.com/identity/protocols/oauth2/scopes
|
|
9
|
-
*/
|
|
10
|
-
static Scopes: {
|
|
11
|
-
account: string;
|
|
12
|
-
"drive.appdata": string;
|
|
13
|
-
imap: string;
|
|
14
|
-
};
|
|
15
|
-
buildAuthUrl(): Promise<string>;
|
|
16
|
-
finishAuth(url: URL): Promise<string>;
|
|
17
|
-
refreshToken(): Promise<string>;
|
|
18
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { DropboxAuthorizer } from "./dropbox";
|
|
2
|
-
import { GoogleAuthorizer } from "./google";
|
|
3
|
-
import { MicrosoftAuthorizer } from "./microsoft";
|
|
4
|
-
export * from "./base";
|
|
5
|
-
export { DropboxAuthorizer, GoogleAuthorizer, MicrosoftAuthorizer };
|
|
6
|
-
export declare const OAuth2Authorizers: {
|
|
7
|
-
dropbox: typeof DropboxAuthorizer;
|
|
8
|
-
google: typeof GoogleAuthorizer;
|
|
9
|
-
microsoft: typeof MicrosoftAuthorizer;
|
|
10
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { OAuth2Authorizer } from "./base.ts";
|
|
2
|
-
/**
|
|
3
|
-
* Ref: https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-auth-code-flow
|
|
4
|
-
*/
|
|
5
|
-
export declare class MicrosoftAuthorizer extends OAuth2Authorizer {
|
|
6
|
-
private session;
|
|
7
|
-
static Scopes: {
|
|
8
|
-
/** Ref: https://learn.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth */
|
|
9
|
-
imap: string;
|
|
10
|
-
onedrive: string;
|
|
11
|
-
};
|
|
12
|
-
buildAuthUrl(): Promise<string>;
|
|
13
|
-
finishAuth(url: URL): Promise<string>;
|
|
14
|
-
refreshToken(): Promise<string>;
|
|
15
|
-
}
|
package/dist/types.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { OAuth2Authorizers } from "./providers";
|
|
2
|
-
export interface TokenData {
|
|
3
|
-
token: string;
|
|
4
|
-
expiresAt?: number;
|
|
5
|
-
scope?: string;
|
|
6
|
-
}
|
|
7
|
-
export interface IOAuth2Options {
|
|
8
|
-
clientId: string;
|
|
9
|
-
clientSecret: string;
|
|
10
|
-
redirectUrl: string;
|
|
11
|
-
scope?: string;
|
|
12
|
-
onSetAccessToken?: (value: TokenData | null) => void;
|
|
13
|
-
onSetRefreshToken?: (value: TokenData | null) => void;
|
|
14
|
-
}
|
|
15
|
-
export interface IOAuth2Account {
|
|
16
|
-
provider: keyof typeof OAuth2Authorizers;
|
|
17
|
-
user: string;
|
|
18
|
-
}
|
package/dist/util.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export declare function getState(): string;
|
|
2
|
-
/**
|
|
3
|
-
* Ref: https://datatracker.ietf.org/doc/html/rfc7636#section-4.1
|
|
4
|
-
* high-entropy cryptographic random STRING using the
|
|
5
|
-
* unreserved characters [A-Z] / [a-z] / [0-9] / "-" / "." / "_" / "~"
|
|
6
|
-
* from Section 2.3 of [RFC3986], with a minimum length of 43 characters
|
|
7
|
-
* and a maximum length of 128 characters.
|
|
8
|
-
*/
|
|
9
|
-
export declare function getCodeVerifier(): string;
|
|
10
|
-
export declare function getCodeChallenge(codeVerifier: string): Promise<{
|
|
11
|
-
codeChallenge: string;
|
|
12
|
-
codeChallengeMethod: string;
|
|
13
|
-
}>;
|