supaapps-auth 1.0.4 → 1.0.5
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/AuthManager.d.ts +3 -1
- package/dist/AuthManager.js +10 -1
- package/package.json +1 -1
- package/src/AuthManager.ts +10 -1
package/dist/AuthManager.d.ts
CHANGED
|
@@ -3,10 +3,12 @@ export declare class AuthManager {
|
|
|
3
3
|
private readonly authServer;
|
|
4
4
|
private readonly realmName;
|
|
5
5
|
private readonly redirectUri;
|
|
6
|
-
|
|
6
|
+
private readonly loginCallback;
|
|
7
|
+
constructor(authServer: string, realmName: string, redirectUri: string, loginCallback: () => void);
|
|
7
8
|
static getInstance<T>(): AuthManager;
|
|
8
9
|
private toBase64Url;
|
|
9
10
|
private generatePKCEPair;
|
|
11
|
+
mustBeLoggedIn(): Promise<void>;
|
|
10
12
|
getLoginWithGoogleUri(): string;
|
|
11
13
|
isLoggedIn(): Promise<boolean>;
|
|
12
14
|
getAccessToken(): Promise<string>;
|
package/dist/AuthManager.js
CHANGED
|
@@ -12,10 +12,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.AuthManager = void 0;
|
|
13
13
|
const crypto_1 = require("crypto");
|
|
14
14
|
class AuthManager {
|
|
15
|
-
constructor(authServer, realmName, redirectUri) {
|
|
15
|
+
constructor(authServer, realmName, redirectUri, loginCallback) {
|
|
16
16
|
this.authServer = null;
|
|
17
17
|
this.realmName = null;
|
|
18
18
|
this.redirectUri = null;
|
|
19
|
+
this.loginCallback = () => { };
|
|
19
20
|
this.toBase64Url = (base64String) => {
|
|
20
21
|
return base64String
|
|
21
22
|
.replace(/\+/g, '-')
|
|
@@ -37,6 +38,7 @@ class AuthManager {
|
|
|
37
38
|
this.authServer = authServer;
|
|
38
39
|
this.realmName = realmName;
|
|
39
40
|
this.redirectUri = redirectUri;
|
|
41
|
+
this.loginCallback = loginCallback;
|
|
40
42
|
AuthManager.instance = this;
|
|
41
43
|
}
|
|
42
44
|
static getInstance() {
|
|
@@ -45,6 +47,13 @@ class AuthManager {
|
|
|
45
47
|
}
|
|
46
48
|
return AuthManager.instance;
|
|
47
49
|
}
|
|
50
|
+
mustBeLoggedIn() {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
if (!(yield this.isLoggedIn())) {
|
|
53
|
+
this.loginCallback();
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
48
57
|
getLoginWithGoogleUri() {
|
|
49
58
|
// get or create codeVerifier and codeChallenge from localstorage
|
|
50
59
|
const { newCodeVerifier, newCodeChallenge } = this.generatePKCEPair();
|
package/package.json
CHANGED
package/src/AuthManager.ts
CHANGED
|
@@ -9,10 +9,13 @@ export class AuthManager {
|
|
|
9
9
|
private readonly realmName: string | null = null;
|
|
10
10
|
|
|
11
11
|
private readonly redirectUri: string | null = null;
|
|
12
|
-
|
|
12
|
+
private readonly loginCallback: () => void = () => {};
|
|
13
|
+
|
|
14
|
+
public constructor(authServer: string, realmName: string, redirectUri: string, loginCallback: () => void) {
|
|
13
15
|
this.authServer = authServer;
|
|
14
16
|
this.realmName = realmName;
|
|
15
17
|
this.redirectUri = redirectUri;
|
|
18
|
+
this.loginCallback = loginCallback;
|
|
16
19
|
AuthManager.instance = this;
|
|
17
20
|
}
|
|
18
21
|
|
|
@@ -46,6 +49,12 @@ export class AuthManager {
|
|
|
46
49
|
|
|
47
50
|
return { newCodeVerifier, newCodeChallenge };
|
|
48
51
|
};
|
|
52
|
+
|
|
53
|
+
public async mustBeLoggedIn(): Promise<void> {
|
|
54
|
+
if (!await this.isLoggedIn()) {
|
|
55
|
+
this.loginCallback();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
49
58
|
public getLoginWithGoogleUri(): string {
|
|
50
59
|
// get or create codeVerifier and codeChallenge from localstorage
|
|
51
60
|
const { newCodeVerifier, newCodeChallenge } = this.generatePKCEPair();
|