piral-oauth2 1.5.3-beta.6956 → 1.5.3-beta.6960
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/esm/client-oauth2.d.ts +140 -0
- package/esm/client-oauth2.js +528 -0
- package/esm/client-oauth2.js.map +1 -0
- package/esm/setup.js +2 -2
- package/esm/setup.js.map +1 -1
- package/esm/types.d.ts +1 -2
- package/lib/client-oauth2.d.ts +140 -0
- package/lib/client-oauth2.js +533 -0
- package/lib/client-oauth2.js.map +1 -0
- package/lib/setup.js +3 -4
- package/lib/setup.js.map +1 -1
- package/lib/types.d.ts +1 -2
- package/package.json +3 -6
- package/piral-oauth2.min.js +1 -1
- package/src/client-oauth2.ts +684 -0
- package/src/setup.ts +7 -7
- package/src/types.ts +1 -3
package/src/setup.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import ClientOAuth2 from 'client-oauth2';
|
|
1
|
+
import { ClientOAuth2, ClientOAuth2Token } from './client-oauth2';
|
|
2
2
|
import { createOAuth2MemoryPersistence } from './utils';
|
|
3
3
|
import { OAuth2Config, OAuth2Client } from './types';
|
|
4
4
|
|
|
@@ -37,11 +37,11 @@ export function setupOAuth2Client(config: OAuth2Config): OAuth2Client {
|
|
|
37
37
|
state,
|
|
38
38
|
});
|
|
39
39
|
|
|
40
|
-
let currentToken:
|
|
40
|
+
let currentToken: ClientOAuth2Token;
|
|
41
41
|
let retrieveToken: () => Promise<string>;
|
|
42
42
|
let getLoginUri: () => string;
|
|
43
43
|
|
|
44
|
-
const setCurrentToken = (token:
|
|
44
|
+
const setCurrentToken = (token: ClientOAuth2Token) => {
|
|
45
45
|
persist.save({
|
|
46
46
|
accessToken: token.accessToken,
|
|
47
47
|
data: token.data,
|
|
@@ -51,7 +51,7 @@ export function setupOAuth2Client(config: OAuth2Config): OAuth2Client {
|
|
|
51
51
|
currentToken = token;
|
|
52
52
|
};
|
|
53
53
|
|
|
54
|
-
const retrieve = (init: Promise<void>, refresh: () => Promise<
|
|
54
|
+
const retrieve = (init: Promise<void>, refresh: () => Promise<ClientOAuth2Token>) => {
|
|
55
55
|
return init.then(() => {
|
|
56
56
|
if (!currentToken) {
|
|
57
57
|
return Promise.reject('Not logged in. Please call `login()` to retrieve a token.');
|
|
@@ -68,11 +68,11 @@ export function setupOAuth2Client(config: OAuth2Config): OAuth2Client {
|
|
|
68
68
|
});
|
|
69
69
|
};
|
|
70
70
|
|
|
71
|
-
const initialize = (load: () => Promise<
|
|
71
|
+
const initialize = (load: () => Promise<ClientOAuth2Token>) => {
|
|
72
72
|
const info = persist.load();
|
|
73
73
|
|
|
74
74
|
if (info) {
|
|
75
|
-
currentToken = client.createToken(info.accessToken, info.refreshToken, info.data);
|
|
75
|
+
currentToken = client.createToken(info.accessToken, info.refreshToken, undefined, info.data);
|
|
76
76
|
return Promise.resolve();
|
|
77
77
|
} else {
|
|
78
78
|
return load().then(
|
|
@@ -109,7 +109,7 @@ export function setupOAuth2Client(config: OAuth2Config): OAuth2Client {
|
|
|
109
109
|
return retrieve(
|
|
110
110
|
init,
|
|
111
111
|
() =>
|
|
112
|
-
new Promise<
|
|
112
|
+
new Promise<ClientOAuth2Token>((resolve) => {
|
|
113
113
|
window[callbackName] = resolve;
|
|
114
114
|
window.open(client.token.getUri());
|
|
115
115
|
}),
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type { Data } from 'client-oauth2';
|
|
2
|
-
|
|
3
1
|
declare module 'piral-core/lib/types/custom' {
|
|
4
2
|
interface PiletCustomApi extends PiralOAuth2Api {}
|
|
5
3
|
}
|
|
@@ -17,7 +15,7 @@ export interface PiralOAuth2Api {
|
|
|
17
15
|
export interface OAuth2TokenInfo {
|
|
18
16
|
accessToken: string;
|
|
19
17
|
refreshToken: string;
|
|
20
|
-
data:
|
|
18
|
+
data: Record<string, string>;
|
|
21
19
|
}
|
|
22
20
|
|
|
23
21
|
/**
|