@dstny/scp-authenticator 0.0.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.d.mts +114 -0
- package/dist/index.d.ts +114 -0
- package/dist/index.js +14636 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +14624 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +36 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import Emittery from 'emittery';
|
|
2
|
+
import { Credentials } from '@dstny/scp-credentials';
|
|
3
|
+
import { SecureStorageHandler } from '@dstny/scp-storage';
|
|
4
|
+
import { AxiosInstance } from 'axios';
|
|
5
|
+
|
|
6
|
+
declare abstract class AbstractAuthenticationApi {
|
|
7
|
+
protected axiosInstance: AxiosInstance;
|
|
8
|
+
constructor(baseURL: string);
|
|
9
|
+
abstract getLoginUrl(redirectUri: string): Promise<string>;
|
|
10
|
+
abstract getToken(authorizationCode: string, redirectUri: string): Promise<Credentials>;
|
|
11
|
+
abstract refreshToken(refreshToken: string, accessToken: string): Promise<Credentials>;
|
|
12
|
+
abstract logout(accessToken?: string, refreshToken?: string): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface JwtPayload {
|
|
16
|
+
[key: string]: any;
|
|
17
|
+
iss?: string | undefined;
|
|
18
|
+
sub?: string | undefined;
|
|
19
|
+
aud?: string | string[] | undefined;
|
|
20
|
+
exp?: number | undefined;
|
|
21
|
+
nbf?: number | undefined;
|
|
22
|
+
iat?: number | undefined;
|
|
23
|
+
jti?: string | undefined;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
declare const STORE_CREDENTIALS_KEY = "sdk-auth-credential";
|
|
27
|
+
declare const STORE_REFRESH_SEPARATION_SECONDS = "sdk-separation-seconds";
|
|
28
|
+
type AuthenticatorState = boolean;
|
|
29
|
+
type LogLevel = 'error' | 'warn' | 'info' | 'debug' | 'trace';
|
|
30
|
+
interface Logger {
|
|
31
|
+
log(...arg: any[]): void;
|
|
32
|
+
error(...arg: any[]): void;
|
|
33
|
+
warn(...arg: any[]): void;
|
|
34
|
+
info(...arg: any[]): void;
|
|
35
|
+
debug(...arg: any[]): void;
|
|
36
|
+
trace(...arg: any[]): void;
|
|
37
|
+
setLevel(level: LogLevel, persist?: boolean): void;
|
|
38
|
+
resetLevel(): void;
|
|
39
|
+
}
|
|
40
|
+
interface AuthenticatorOptions {
|
|
41
|
+
credentials?: Credentials;
|
|
42
|
+
logger?: Logger;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
declare class Authenticator extends Emittery {
|
|
46
|
+
private readonly api;
|
|
47
|
+
private readonly secureStorage;
|
|
48
|
+
private readonly logger?;
|
|
49
|
+
private readonly initialCredentials?;
|
|
50
|
+
private _state?;
|
|
51
|
+
private _credentials?;
|
|
52
|
+
private _jwtPayload?;
|
|
53
|
+
private isSetup;
|
|
54
|
+
private refreshTokenRunnerTimer?;
|
|
55
|
+
private refreshSeparationMilliseconds;
|
|
56
|
+
private refreshTokenPromise?;
|
|
57
|
+
private removeCredentialStorageUpdates?;
|
|
58
|
+
private unsubscribeListenerAdded?;
|
|
59
|
+
private unsubscribeUpdateState?;
|
|
60
|
+
private timers;
|
|
61
|
+
get jwtPayload(): JwtPayload | undefined;
|
|
62
|
+
get credentials(): Credentials | undefined;
|
|
63
|
+
get state(): AuthenticatorState;
|
|
64
|
+
constructor(api: AbstractAuthenticationApi, secureStorage: SecureStorageHandler, options?: AuthenticatorOptions);
|
|
65
|
+
setup(): Promise<void>;
|
|
66
|
+
destroy(): Promise<void>;
|
|
67
|
+
private wait;
|
|
68
|
+
getLoginUrl(redirectUri: string): Promise<string>;
|
|
69
|
+
signIn(authorizationCode: string, redirectUri: string): Promise<Credentials>;
|
|
70
|
+
signOut(remote?: boolean): Promise<void>;
|
|
71
|
+
sanityCheck(): Promise<void>;
|
|
72
|
+
isTokenValid(): boolean;
|
|
73
|
+
signInWithCredentials(credentials: Credentials): Promise<Credentials>;
|
|
74
|
+
private _signInWithCredentials;
|
|
75
|
+
private _setupRefreshTokenRunner;
|
|
76
|
+
refreshToken(): Promise<Credentials>;
|
|
77
|
+
refreshTokenWithRetry(): Promise<Credentials>;
|
|
78
|
+
private _refreshToken;
|
|
79
|
+
private storeCredentials;
|
|
80
|
+
private assertIsSetup;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
declare enum AuthenticatorEvents {
|
|
84
|
+
CREDENTIALS = "CREDENTIALS",
|
|
85
|
+
ACCESS_TOKEN = "ACCESS_TOKEN",
|
|
86
|
+
JWT_PAYLOAD = "JWT_PAYLOAD",
|
|
87
|
+
STATE_CHANGE = "STATE_CHANGE",
|
|
88
|
+
ERROR = "ERROR"
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
declare class OAuthApi extends AbstractAuthenticationApi {
|
|
92
|
+
readonly clientId: string;
|
|
93
|
+
readonly scope: string;
|
|
94
|
+
readonly authorizationRoute: string;
|
|
95
|
+
private readonly baseURL;
|
|
96
|
+
constructor(baseURL: string, clientId: string, authorizationRoute: string, scope: string);
|
|
97
|
+
getLoginUrl(redirectUri: string): Promise<string>;
|
|
98
|
+
getToken(authorizationCode: string, redirectUri: string): Promise<Credentials>;
|
|
99
|
+
loginWithUsernamePassword(username: string, password: string): Promise<Credentials>;
|
|
100
|
+
refreshToken(refreshToken: string, accessToken: string): Promise<Credentials>;
|
|
101
|
+
logout(_redirectUri?: string): Promise<void>;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
declare class SmgAuthApi extends AbstractAuthenticationApi {
|
|
105
|
+
readonly clientId: string;
|
|
106
|
+
readonly realm: string;
|
|
107
|
+
constructor(baseURL: string, realm: string, clientId: string);
|
|
108
|
+
getLoginUrl(redirectUri: string): Promise<string>;
|
|
109
|
+
getToken(authorizationCode: string, redirectUri: string): Promise<Credentials>;
|
|
110
|
+
refreshToken(refreshToken: string, accessToken: string): Promise<Credentials>;
|
|
111
|
+
logout(refreshToken: string, accessToken: string): Promise<void>;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export { AbstractAuthenticationApi, AuthenticatorEvents, AuthenticatorOptions, AuthenticatorState, LogLevel, Logger, OAuthApi, STORE_CREDENTIALS_KEY, STORE_REFRESH_SEPARATION_SECONDS, SmgAuthApi, Authenticator as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import Emittery from 'emittery';
|
|
2
|
+
import { Credentials } from '@dstny/scp-credentials';
|
|
3
|
+
import { SecureStorageHandler } from '@dstny/scp-storage';
|
|
4
|
+
import { AxiosInstance } from 'axios';
|
|
5
|
+
|
|
6
|
+
declare abstract class AbstractAuthenticationApi {
|
|
7
|
+
protected axiosInstance: AxiosInstance;
|
|
8
|
+
constructor(baseURL: string);
|
|
9
|
+
abstract getLoginUrl(redirectUri: string): Promise<string>;
|
|
10
|
+
abstract getToken(authorizationCode: string, redirectUri: string): Promise<Credentials>;
|
|
11
|
+
abstract refreshToken(refreshToken: string, accessToken: string): Promise<Credentials>;
|
|
12
|
+
abstract logout(accessToken?: string, refreshToken?: string): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface JwtPayload {
|
|
16
|
+
[key: string]: any;
|
|
17
|
+
iss?: string | undefined;
|
|
18
|
+
sub?: string | undefined;
|
|
19
|
+
aud?: string | string[] | undefined;
|
|
20
|
+
exp?: number | undefined;
|
|
21
|
+
nbf?: number | undefined;
|
|
22
|
+
iat?: number | undefined;
|
|
23
|
+
jti?: string | undefined;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
declare const STORE_CREDENTIALS_KEY = "sdk-auth-credential";
|
|
27
|
+
declare const STORE_REFRESH_SEPARATION_SECONDS = "sdk-separation-seconds";
|
|
28
|
+
type AuthenticatorState = boolean;
|
|
29
|
+
type LogLevel = 'error' | 'warn' | 'info' | 'debug' | 'trace';
|
|
30
|
+
interface Logger {
|
|
31
|
+
log(...arg: any[]): void;
|
|
32
|
+
error(...arg: any[]): void;
|
|
33
|
+
warn(...arg: any[]): void;
|
|
34
|
+
info(...arg: any[]): void;
|
|
35
|
+
debug(...arg: any[]): void;
|
|
36
|
+
trace(...arg: any[]): void;
|
|
37
|
+
setLevel(level: LogLevel, persist?: boolean): void;
|
|
38
|
+
resetLevel(): void;
|
|
39
|
+
}
|
|
40
|
+
interface AuthenticatorOptions {
|
|
41
|
+
credentials?: Credentials;
|
|
42
|
+
logger?: Logger;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
declare class Authenticator extends Emittery {
|
|
46
|
+
private readonly api;
|
|
47
|
+
private readonly secureStorage;
|
|
48
|
+
private readonly logger?;
|
|
49
|
+
private readonly initialCredentials?;
|
|
50
|
+
private _state?;
|
|
51
|
+
private _credentials?;
|
|
52
|
+
private _jwtPayload?;
|
|
53
|
+
private isSetup;
|
|
54
|
+
private refreshTokenRunnerTimer?;
|
|
55
|
+
private refreshSeparationMilliseconds;
|
|
56
|
+
private refreshTokenPromise?;
|
|
57
|
+
private removeCredentialStorageUpdates?;
|
|
58
|
+
private unsubscribeListenerAdded?;
|
|
59
|
+
private unsubscribeUpdateState?;
|
|
60
|
+
private timers;
|
|
61
|
+
get jwtPayload(): JwtPayload | undefined;
|
|
62
|
+
get credentials(): Credentials | undefined;
|
|
63
|
+
get state(): AuthenticatorState;
|
|
64
|
+
constructor(api: AbstractAuthenticationApi, secureStorage: SecureStorageHandler, options?: AuthenticatorOptions);
|
|
65
|
+
setup(): Promise<void>;
|
|
66
|
+
destroy(): Promise<void>;
|
|
67
|
+
private wait;
|
|
68
|
+
getLoginUrl(redirectUri: string): Promise<string>;
|
|
69
|
+
signIn(authorizationCode: string, redirectUri: string): Promise<Credentials>;
|
|
70
|
+
signOut(remote?: boolean): Promise<void>;
|
|
71
|
+
sanityCheck(): Promise<void>;
|
|
72
|
+
isTokenValid(): boolean;
|
|
73
|
+
signInWithCredentials(credentials: Credentials): Promise<Credentials>;
|
|
74
|
+
private _signInWithCredentials;
|
|
75
|
+
private _setupRefreshTokenRunner;
|
|
76
|
+
refreshToken(): Promise<Credentials>;
|
|
77
|
+
refreshTokenWithRetry(): Promise<Credentials>;
|
|
78
|
+
private _refreshToken;
|
|
79
|
+
private storeCredentials;
|
|
80
|
+
private assertIsSetup;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
declare enum AuthenticatorEvents {
|
|
84
|
+
CREDENTIALS = "CREDENTIALS",
|
|
85
|
+
ACCESS_TOKEN = "ACCESS_TOKEN",
|
|
86
|
+
JWT_PAYLOAD = "JWT_PAYLOAD",
|
|
87
|
+
STATE_CHANGE = "STATE_CHANGE",
|
|
88
|
+
ERROR = "ERROR"
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
declare class OAuthApi extends AbstractAuthenticationApi {
|
|
92
|
+
readonly clientId: string;
|
|
93
|
+
readonly scope: string;
|
|
94
|
+
readonly authorizationRoute: string;
|
|
95
|
+
private readonly baseURL;
|
|
96
|
+
constructor(baseURL: string, clientId: string, authorizationRoute: string, scope: string);
|
|
97
|
+
getLoginUrl(redirectUri: string): Promise<string>;
|
|
98
|
+
getToken(authorizationCode: string, redirectUri: string): Promise<Credentials>;
|
|
99
|
+
loginWithUsernamePassword(username: string, password: string): Promise<Credentials>;
|
|
100
|
+
refreshToken(refreshToken: string, accessToken: string): Promise<Credentials>;
|
|
101
|
+
logout(_redirectUri?: string): Promise<void>;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
declare class SmgAuthApi extends AbstractAuthenticationApi {
|
|
105
|
+
readonly clientId: string;
|
|
106
|
+
readonly realm: string;
|
|
107
|
+
constructor(baseURL: string, realm: string, clientId: string);
|
|
108
|
+
getLoginUrl(redirectUri: string): Promise<string>;
|
|
109
|
+
getToken(authorizationCode: string, redirectUri: string): Promise<Credentials>;
|
|
110
|
+
refreshToken(refreshToken: string, accessToken: string): Promise<Credentials>;
|
|
111
|
+
logout(refreshToken: string, accessToken: string): Promise<void>;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export { AbstractAuthenticationApi, AuthenticatorEvents, AuthenticatorOptions, AuthenticatorState, LogLevel, Logger, OAuthApi, STORE_CREDENTIALS_KEY, STORE_REFRESH_SEPARATION_SECONDS, SmgAuthApi, Authenticator as default };
|