@cloudbase/oauth 0.0.5-alpha.0 → 0.1.1-alpha

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.
Files changed (86) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +137 -5
  3. package/app/index.d.ts +28 -0
  4. package/app/index.js +54 -0
  5. package/app/index.js.map +1 -0
  6. package/app/internal.d.ts +12 -0
  7. package/app/internal.js +25 -0
  8. package/app/internal.js.map +1 -0
  9. package/app/openuri.d.ts +20 -0
  10. package/app/openuri.js +104 -0
  11. package/app/openuri.js.map +1 -0
  12. package/app/request.d.ts +18 -0
  13. package/app/request.js +44 -0
  14. package/app/request.js.map +1 -0
  15. package/app/storage.d.ts +41 -0
  16. package/app/storage.js +35 -0
  17. package/app/storage.js.map +1 -0
  18. package/{dist/auth → auth}/consts.d.ts +21 -1
  19. package/auth/consts.js +57 -0
  20. package/auth/consts.js.map +1 -0
  21. package/auth/index.d.ts +193 -0
  22. package/auth/index.js +403 -0
  23. package/auth/index.js.map +1 -0
  24. package/{dist/auth → auth}/models.d.ts +35 -25
  25. package/auth/models.js +3 -0
  26. package/auth/models.js.map +1 -0
  27. package/captcha/index.d.ts +45 -0
  28. package/captcha/index.js +133 -0
  29. package/captcha/index.js.map +1 -0
  30. package/index.d.ts +8 -0
  31. package/index.js +17 -0
  32. package/index.js.map +1 -0
  33. package/{dist/oauth2client → oauthclient}/consts.d.ts +1 -22
  34. package/oauthclient/consts.js +53 -0
  35. package/oauthclient/consts.js.map +1 -0
  36. package/oauthclient/index.d.ts +18 -0
  37. package/oauthclient/index.js +21 -0
  38. package/oauthclient/index.js.map +1 -0
  39. package/oauthclient/interface.d.ts +25 -0
  40. package/oauthclient/interface.js +10 -0
  41. package/oauthclient/interface.js.map +1 -0
  42. package/{dist/oauth2client → oauthclient}/models.d.ts +5 -13
  43. package/oauthclient/models.js +3 -0
  44. package/oauthclient/models.js.map +1 -0
  45. package/oauthclient/oauthclient.d.ts +142 -0
  46. package/oauthclient/oauthclient.js +399 -0
  47. package/oauthclient/oauthclient.js.map +1 -0
  48. package/package.json +29 -33
  49. package/utils/single-promise.d.ts +18 -0
  50. package/utils/single-promise.js +48 -0
  51. package/utils/single-promise.js.map +1 -0
  52. package/utils/uuid.d.ts +5 -0
  53. package/utils/uuid.js +16 -0
  54. package/utils/uuid.js.map +1 -0
  55. package/.eslintignore +0 -2
  56. package/.eslintrc +0 -26
  57. package/dist/auth/apis.d.ts +0 -44
  58. package/dist/auth/apis.js +0 -448
  59. package/dist/auth/consts.js +0 -35
  60. package/dist/auth/models.js +0 -3
  61. package/dist/captcha/captcha.d.ts +0 -35
  62. package/dist/captcha/captcha.js +0 -262
  63. package/dist/index.d.ts +0 -9
  64. package/dist/index.js +0 -234
  65. package/dist/oauth2client/consts.js +0 -73
  66. package/dist/oauth2client/interface.d.ts +0 -15
  67. package/dist/oauth2client/interface.js +0 -10
  68. package/dist/oauth2client/models.js +0 -3
  69. package/dist/oauth2client/oauth2client.d.ts +0 -70
  70. package/dist/oauth2client/oauth2client.js +0 -618
  71. package/dist/utils/function/single-promise.d.ts +0 -5
  72. package/dist/utils/function/single-promise.js +0 -89
  73. package/dist/utils/uuid.d.ts +0 -1
  74. package/dist/utils/uuid.js +0 -12
  75. package/src/auth/apis.ts +0 -507
  76. package/src/auth/consts.ts +0 -30
  77. package/src/auth/models.ts +0 -178
  78. package/src/captcha/captcha.ts +0 -217
  79. package/src/index.ts +0 -162
  80. package/src/oauth2client/consts.ts +0 -69
  81. package/src/oauth2client/interface.ts +0 -57
  82. package/src/oauth2client/models.ts +0 -61
  83. package/src/oauth2client/oauth2client.ts +0 -606
  84. package/src/utils/function/single-promise.ts +0 -40
  85. package/src/utils/uuid.ts +0 -11
  86. package/tsconfig.json +0 -44
@@ -1,28 +1,26 @@
1
- interface BaseRequest {
2
- client_id?: string;
3
- }
4
- export interface SignInRequest extends BaseRequest {
1
+ export interface SignInRequest {
5
2
  username?: string;
6
3
  password?: string;
7
- verification_code?: string;
8
4
  verification_token?: string;
9
5
  }
10
- export interface SignInWithProviderRequest extends BaseRequest {
6
+ export interface SignInWithProviderRequest {
11
7
  provider_token: string;
8
+ provider_id?: string;
12
9
  }
13
- export interface SignUpRequest extends BaseRequest {
10
+ export interface SignUpRequest {
14
11
  phone_number?: string;
15
12
  email?: string;
16
13
  verification_code?: string;
17
14
  verification_token?: string;
18
15
  provider_token?: string;
16
+ username?: string;
19
17
  password?: string;
20
18
  name?: string;
21
19
  gender?: string;
22
20
  picture?: string;
23
21
  locale?: string;
24
22
  }
25
- export interface GetVerificationRequest extends BaseRequest {
23
+ export interface GetVerificationRequest {
26
24
  phone_number?: string;
27
25
  email?: string;
28
26
  target?: string | 'ANY';
@@ -35,14 +33,14 @@ export interface GetVerificationResponse {
35
33
  export interface VerifyResponse {
36
34
  verification_token?: string;
37
35
  }
38
- export interface VerifyRequest extends BaseRequest {
36
+ export interface VerifyRequest {
39
37
  verification_code: string;
40
38
  verification_id?: string;
41
39
  }
42
40
  export interface ProviderBindRequest {
43
41
  provider_token: string;
44
42
  }
45
- export interface GrantProviderTokenRequest extends BaseRequest {
43
+ export interface GrantProviderTokenRequest {
46
44
  provider_id: string;
47
45
  provider_redirect_uri?: string;
48
46
  provider_code?: string;
@@ -53,7 +51,7 @@ export interface GrantProviderTokenResponse {
53
51
  provider_token: string;
54
52
  expires_in: number;
55
53
  }
56
- export interface PatchProviderTokenRequest extends BaseRequest {
54
+ export interface PatchProviderTokenRequest {
57
55
  provider_token: string;
58
56
  provider_params: {
59
57
  encryptedData: string;
@@ -77,7 +75,7 @@ export interface GenProviderRedirectUriResponse {
77
75
  uri: string;
78
76
  signout_uri?: string;
79
77
  }
80
- export interface BindWithProviderRequest extends BaseRequest {
78
+ export interface BindWithProviderRequest {
81
79
  provider_token: string;
82
80
  }
83
81
  export interface BindWithProviderRequest {
@@ -91,7 +89,6 @@ export interface UserProfileProvider {
91
89
  export interface UserProfile {
92
90
  name?: string;
93
91
  picture?: string;
94
- avatarUrl?: string;
95
92
  username?: string;
96
93
  email?: string;
97
94
  email_verified?: boolean;
@@ -102,10 +99,7 @@ export interface UserProfile {
102
99
  zoneinfo?: string;
103
100
  locale?: string;
104
101
  created_from?: string;
105
- sub?: string;
106
- uid?: string;
107
102
  }
108
- export declare type UserInfo = UserProfile;
109
103
  export interface ProviderProfile {
110
104
  provider_id: string;
111
105
  phone_number?: string;
@@ -113,7 +107,7 @@ export interface ProviderProfile {
113
107
  export interface TransByProviderRequest {
114
108
  provider_token: string;
115
109
  }
116
- export interface GrantTokenRequest extends BaseRequest {
110
+ export interface GrantTokenRequest {
117
111
  client_secret?: string;
118
112
  code?: string;
119
113
  grant_type?: string;
@@ -122,27 +116,43 @@ export interface GrantTokenRequest extends BaseRequest {
122
116
  refresh_token?: string;
123
117
  scope?: string;
124
118
  }
125
- export interface UnbindProviderRequest extends BaseRequest {
119
+ export interface UnbindProviderRequest {
126
120
  provider_id: string;
127
121
  }
128
- export interface CheckPasswordrRequest extends BaseRequest {
122
+ export interface CheckPasswordrRequest {
129
123
  password: string;
130
124
  }
131
- export interface BindPhoneRequest extends BaseRequest {
125
+ export interface BindPhoneRequest {
132
126
  phone_number: string;
133
127
  sudo_token: string;
134
128
  verification_token: string;
135
129
  }
136
- export interface SetPasswordRequest extends BaseRequest {
130
+ export interface SetPasswordRequest {
131
+ new_password: string;
132
+ sudo_token: string;
133
+ }
134
+ export interface SetPasswordRequest {
137
135
  new_password: string;
138
136
  sudo_token: string;
139
137
  }
140
- export interface ChangeBindedProviderRequest extends BaseRequest {
138
+ export interface UpdatePasswordRequest {
139
+ old_password: string;
140
+ new_password: string;
141
+ }
142
+ export interface SudoRequest {
143
+ password?: string;
144
+ verification_token?: string;
145
+ }
146
+ export interface SudoResponse {
147
+ sudo_token?: string;
148
+ }
149
+ export interface ChangeBoundProviderRequest {
141
150
  trans_token: string;
142
151
  provider_id: string;
143
152
  }
144
- export declare type ChangeBindedProviderResponse = BaseRequest;
145
- export interface QueryUserProfileReq extends BaseRequest {
153
+ export interface ChangeBoundProviderResponse {
154
+ client_id: string;
155
+ }
156
+ export interface QueryUserProfileReq {
146
157
  appended_params: string;
147
158
  }
148
- export {};
package/auth/models.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=models.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"models.js","sourceRoot":"","sources":["../../src/auth/models.ts"],"names":[],"mappings":""}
@@ -0,0 +1,45 @@
1
+ import { App, RequestOptions, RequestFn, Storage, OpenURIWithCallback } from "../app";
2
+ export interface CaptchaOptions {
3
+ request: RequestFn;
4
+ storage: Storage;
5
+ openURIWithCallback: OpenURIWithCallback;
6
+ }
7
+ export interface CaptchaInitOptions {
8
+ request?: RequestFn;
9
+ }
10
+ export declare function getCaptcha(app: App, opts?: CaptchaInitOptions): Captcha;
11
+ export interface CaptchaToken {
12
+ captcha_token: string;
13
+ expires_in: number;
14
+ expires_at?: Date | null;
15
+ }
16
+ export interface CaptchaRequestOptions extends RequestOptions {
17
+ withCaptcha?: boolean;
18
+ }
19
+ export interface GetCaptchaResponse {
20
+ captcha_token?: string;
21
+ expires_in?: number;
22
+ url?: string;
23
+ }
24
+ export declare class Captcha {
25
+ private _config;
26
+ private _tokenSectionName;
27
+ /**
28
+ * constructor
29
+ * @param {CaptchaOptions} opts
30
+ */
31
+ constructor(opts: CaptchaOptions);
32
+ /**
33
+ * request http like simple fetch api, exp:request('/v1/user/me', {withCredentials:true})
34
+ * @param {string} url
35
+ * @param {AuthClientRequestOptions} options
36
+ */
37
+ request<T>(url: string, options?: CaptchaRequestOptions): Promise<T>;
38
+ /**
39
+ * _getCaptchaToken get captcha token
40
+ */
41
+ private _getCaptchaToken;
42
+ private _appendCaptchaTokenToURL;
43
+ private _saveCaptchaToken;
44
+ private _findCaptchaToken;
45
+ }
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Captcha = exports.getCaptcha = void 0;
4
+ const internal_1 = require("../app/internal");
5
+ function getCaptcha(app, opts) {
6
+ return internal_1._getComponent(app, "captcha", () => {
7
+ const initOpts = {
8
+ request: app.options.request,
9
+ storage: app.options.storage,
10
+ openURIWithCallback: app.options.openURIWithCallback,
11
+ };
12
+ if (opts && opts.request) {
13
+ initOpts.request = opts.request;
14
+ }
15
+ return new Captcha(initOpts);
16
+ });
17
+ }
18
+ exports.getCaptcha = getCaptcha;
19
+ const GET_CAPTCHA_URL = '/auth/v1/captcha/init';
20
+ class Captcha {
21
+ /**
22
+ * constructor
23
+ * @param {CaptchaOptions} opts
24
+ */
25
+ constructor(opts) {
26
+ this._config = opts;
27
+ this._tokenSectionName = 'captcha_';
28
+ }
29
+ /**
30
+ * request http like simple fetch api, exp:request('/v1/user/me', {withCredentials:true})
31
+ * @param {string} url
32
+ * @param {AuthClientRequestOptions} options
33
+ */
34
+ async request(url, options) {
35
+ if (!options) {
36
+ options = {};
37
+ }
38
+ if (!options.method) {
39
+ options.method = 'GET';
40
+ }
41
+ const state = options.method + ":" + url;
42
+ let reqURL = url;
43
+ if (options.withCaptcha) {
44
+ reqURL = await this._appendCaptchaTokenToURL(url, state, false);
45
+ }
46
+ try {
47
+ return this._config.request(reqURL, options);
48
+ }
49
+ catch (err) {
50
+ if (err.error === 'captcha_required' || err.error === 'captcha_invalid') {
51
+ url = await this._appendCaptchaTokenToURL(url, state, err.error === 'captcha_invalid');
52
+ return this._config.request(url, options);
53
+ }
54
+ else {
55
+ return Promise.reject(err);
56
+ }
57
+ }
58
+ }
59
+ /**
60
+ * _getCaptchaToken get captcha token
61
+ */
62
+ async _getCaptchaToken(forceNewToken, state) {
63
+ if (!forceNewToken) {
64
+ // if local has captcha token then return
65
+ const captchaToken = await this._findCaptchaToken();
66
+ if (captchaToken) {
67
+ return captchaToken;
68
+ }
69
+ }
70
+ const redirectURL = window.location.origin + window.location.pathname;
71
+ const captchaTokenResp = await this._config.request(GET_CAPTCHA_URL, {
72
+ method: 'POST',
73
+ body: {
74
+ redirect_uri: redirectURL,
75
+ state: state
76
+ },
77
+ withBasicAuth: true,
78
+ });
79
+ if (captchaTokenResp.captcha_token) {
80
+ const captchaToken = {
81
+ captcha_token: captchaTokenResp.captcha_token,
82
+ expires_in: captchaTokenResp.expires_in,
83
+ };
84
+ await this._saveCaptchaToken(captchaToken);
85
+ return captchaTokenResp.captcha_token;
86
+ }
87
+ const callbackData = await this._config.openURIWithCallback(captchaTokenResp.url, { width: '355px', height: '355px' });
88
+ const captchaToken = {
89
+ captcha_token: callbackData.captcha_token,
90
+ expires_in: Number(callbackData.expires_in)
91
+ };
92
+ await this._saveCaptchaToken(captchaToken);
93
+ return captchaToken.captcha_token;
94
+ }
95
+ async _appendCaptchaTokenToURL(url, state, forceNewToken) {
96
+ const captchaToken = await this._getCaptchaToken(forceNewToken, state);
97
+ if (url.indexOf("?") > 0) {
98
+ url += "&captcha_token=" + captchaToken;
99
+ }
100
+ else {
101
+ url += "?captcha_token=" + captchaToken;
102
+ }
103
+ return url;
104
+ }
105
+ async _saveCaptchaToken(token) {
106
+ token.expires_at = new Date(Date.now() + (token.expires_in - 10) * 1000);
107
+ const tokenStr = JSON.stringify(token);
108
+ await this._config.storage.setItem(this._tokenSectionName, tokenStr);
109
+ }
110
+ async _findCaptchaToken() {
111
+ const tokenStr = await this._config.storage.getItem(this._tokenSectionName);
112
+ if (tokenStr !== undefined && tokenStr !== null) {
113
+ try {
114
+ const captchaToken = JSON.parse(tokenStr);
115
+ if (captchaToken && captchaToken.expires_at) {
116
+ captchaToken.expires_at = new Date(captchaToken.expires_at);
117
+ }
118
+ const isExpired = captchaToken.expires_at < new Date();
119
+ if (isExpired) {
120
+ return null;
121
+ }
122
+ return captchaToken.captcha_token;
123
+ }
124
+ catch (error) {
125
+ await this._config.storage.removeItem(this._tokenSectionName);
126
+ return null;
127
+ }
128
+ }
129
+ return null;
130
+ }
131
+ }
132
+ exports.Captcha = Captcha;
133
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/captcha/index.ts"],"names":[],"mappings":";;;AACA,8CAA8C;AAY9C,SAAgB,UAAU,CAAC,GAAQ,EAAE,IAAyB;IAC1D,OAAO,wBAAa,CAAU,GAAG,EAAE,SAAS,EAAE,GAAY,EAAE;QACxD,MAAM,QAAQ,GAAG;YACb,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,OAAO;YAC5B,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,OAAO;YAC5B,mBAAmB,EAAE,GAAG,CAAC,OAAO,CAAC,mBAAmB;SACvD,CAAA;QACD,IAAI,IAAI,IAAI,IAAI,CAAC,OAAO,EAAE;YACtB,QAAQ,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAA;SAClC;QACD,OAAO,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAA;IAChC,CAAC,CAAC,CAAC;AACP,CAAC;AAZD,gCAYC;AAkBD,MAAM,eAAe,GAAG,uBAAuB,CAAA;AAE/C,MAAa,OAAO;IAIhB;;;OAGG;IACH,YAAY,IAAoB;QAC5B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;QACnB,IAAI,CAAC,iBAAiB,GAAG,UAAU,CAAA;IACvC,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,OAAO,CAChB,GAAW,EACX,OAA+B;QAE/B,IAAI,CAAC,OAAO,EAAE;YACV,OAAO,GAAG,EAAE,CAAC;SAChB;QACD,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;YACjB,OAAO,CAAC,MAAM,GAAG,KAAK,CAAA;SACzB;QACD,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,GAAG,GAAG,GAAG,GAAG,CAAA;QACxC,IAAI,MAAM,GAAG,GAAG,CAAC;QACjB,IAAI,OAAO,CAAC,WAAW,EAAE;YACrB,MAAM,GAAG,MAAM,IAAI,CA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Q,CAAC,CAAC;IACzE,CAAC;IAEO,KAAK,CAAC,iBAAiB;QAC3B,MAAM,QAAQ,GAAW,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CACvD,IAAI,CAAC,iBAAiB,CACzB,CAAC;QACF,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,KAAK,IAAI,EAAE;YAC7C,IAAI;gBACA,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;gBAC1C,IAAI,YAAY,IAAI,YAAY,CAAC,UAAU,EAAE;oBACzC,YAAY,CAAC,UAAU,GAAG,IAAI,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;iBAC/D;gBACD,MAAM,SAAS,GAAG,YAAY,CAAC,UAAU,GAAG,IAAI,IAAI,EAAE,CAAC;gBACvD,IAAI,SAAS,EAAE;oBACX,OAAO,IAAI,CAAA;iBACd;gBACD,OAAO,YAAY,CAAC,aAAa,CAAA;aACpC;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;gBAC9D,OAAO,IAAI,CAAA;aACd;SACJ;QACD,OAAO,IAAI,CAAA;IACf,CAAC;CACJ;AA1HD,0BA0HC"}
package/index.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { Auth } from './auth';
2
+ import { App, Options } from './app';
3
+ export declare function initializeClient(options: Options): Client;
4
+ export declare class Client {
5
+ auth: Auth;
6
+ app: App;
7
+ constructor(initOptions: Options);
8
+ }
package/index.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Client = exports.initializeClient = void 0;
4
+ const auth_1 = require("./auth");
5
+ const app_1 = require("./app");
6
+ function initializeClient(options) {
7
+ return new Client(options);
8
+ }
9
+ exports.initializeClient = initializeClient;
10
+ class Client {
11
+ constructor(initOptions) {
12
+ this.app = app_1.initializeApp(initOptions);
13
+ this.auth = auth_1.getAuth(this.app);
14
+ }
15
+ }
16
+ exports.Client = Client;
17
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,iCAAqC;AACrC,+BAAkD;AAElD,SAAgB,gBAAgB,CAAC,OAAgB;IAC7C,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC;AAC/B,CAAC;AAFD,4CAEC;AAED,MAAa,MAAM;IAIf,YAAY,WAAoB;QAC5B,IAAI,CAAC,GAAG,GAAG,mBAAa,CAAC,WAAW,CAAC,CAAA;QACrC,IAAI,CAAC,IAAI,GAAG,cAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IACjC,CAAC;CACJ;AARD,wBAQC"}
@@ -36,32 +36,11 @@ export declare enum ErrorType {
36
36
  INTERNAL = "internal",
37
37
  UNAVAILABLE = "unavailable",
38
38
  DATA_LOSS = "data_loss",
39
- CAPTCHA_REQUIRED = "captcha_required",
40
- CAPTCHA_INVALID = "captcha_invalid",
41
- INVALID_PASSWORD = "invalid_password",
42
- INVALID_STATUS = "invalid_status",
43
- USER_PENDING = "user_pending",
44
- USER_BLOCKED = "user_blocked",
45
- INVALID_VERIFICATION_CODE = "invalid_verification_code",
46
- TWO_FACTOR_REQUIRED = "two_factor_required",
47
- INVALID_TWO_FACTOR = "invalid_two_factor",
48
- INVALID_TWO_FACTOR_RECOVERY = "invalid_two_factor_recovery",
49
- UNDER_REVIEW = "under_review",
50
- INVALID_REQUEST = "invalid_request",
51
- UNAUTHORIZED_CLIENT = "unauthorized_client",
52
39
  ACCESS_DENIED = "access_denied",
53
40
  UNSUPPORTED_RESPONSE_TYPE = "unsupported_response_type",
54
41
  INVALID_SCOPE = "invalid_scope",
55
42
  INVALID_GRANT = "invalid_grant",
56
43
  SERVER_ERROR = "server_error",
57
44
  TEMPORARILY_UNAVAILABLE = "temporarily_unavailable",
58
- INTERACTION_REQUIRED = "interaction_required",
59
- LOGIN_REQUIRED = "login_required",
60
- ACCOUNT_SELECTION_REQUIRED = "account_selection_required",
61
- CONSENT_REQUIRED = "consent_required",
62
- INVALID_REQUEST_URI = "invalid_request_uri",
63
- INVALID_REQUEST_OBJECT = "invalid_request_object",
64
- REQUEST_NOT_SUPPORTED = "request_not_supported",
65
- REQUEST_URI_NOT_SUPPORTED = "request_uri_not_supported",
66
- REGISTRATION_NOT_SUPPORTED = "registration_not_supported"
45
+ INTERACTION_REQUIRED = "interaction_required"
67
46
  }
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ErrorType = exports.Syntax = void 0;
4
+ var Syntax;
5
+ (function (Syntax) {
6
+ Syntax["CLIENT_ID"] = "client_id";
7
+ Syntax["CLIENT_SECRET"] = "client_secret";
8
+ Syntax["RESPONSE_TYPE"] = "response_type";
9
+ Syntax["SCOPE"] = "scope";
10
+ Syntax["STATE"] = "state";
11
+ Syntax["REDIRECT_URI"] = "redirect_uri";
12
+ Syntax["ERROR"] = "error";
13
+ Syntax["ERROR_DESCRIPTION"] = "error_description";
14
+ Syntax["ERROR_URI"] = "error_uri";
15
+ Syntax["GRANT_TYPE"] = "grant_type";
16
+ Syntax["CODE"] = "code";
17
+ Syntax["ACCESS_TOKEN"] = "access_token";
18
+ Syntax["TOKEN_TYPE"] = "token_type";
19
+ Syntax["EXPIRES_IN"] = "expires_in";
20
+ Syntax["USERNAME"] = "username";
21
+ Syntax["PASSWORD"] = "password";
22
+ Syntax["REFRESH_TOKEN"] = "refresh_token";
23
+ })(Syntax = exports.Syntax || (exports.Syntax = {}));
24
+ var ErrorType;
25
+ (function (ErrorType) {
26
+ ErrorType["UNREACHABLE"] = "unreachable";
27
+ ErrorType["LOCAL"] = "local";
28
+ ErrorType["CANCELLED"] = "cancelled";
29
+ ErrorType["UNKNOWN"] = "unknown";
30
+ ErrorType["INVALID_ARGUMENT"] = "invalid_argument";
31
+ ErrorType["DEADLINE_EXCEEDED"] = "deadline_exceeded";
32
+ ErrorType["NOT_FOUND"] = "not_found";
33
+ ErrorType["ALREADY_EXISTS"] = "already_exists";
34
+ ErrorType["PERMISSION_DENIED"] = "permission_denied";
35
+ ErrorType["UNAUTHENTICATED"] = "unauthenticated";
36
+ ErrorType["RESOURCE_EXHAUSTED"] = "resource_exhausted";
37
+ ErrorType["FAILED_PRECONDITION"] = "failed_precondition";
38
+ ErrorType["ABORTED"] = "aborted";
39
+ ErrorType["OUT_OF_RANGE"] = "out_of_range";
40
+ ErrorType["UNIMPLEMENTED"] = "unimplemented";
41
+ ErrorType["INTERNAL"] = "internal";
42
+ ErrorType["UNAVAILABLE"] = "unavailable";
43
+ ErrorType["DATA_LOSS"] = "data_loss";
44
+ // CommonError
45
+ ErrorType["ACCESS_DENIED"] = "access_denied";
46
+ ErrorType["UNSUPPORTED_RESPONSE_TYPE"] = "unsupported_response_type";
47
+ ErrorType["INVALID_SCOPE"] = "invalid_scope";
48
+ ErrorType["INVALID_GRANT"] = "invalid_grant";
49
+ ErrorType["SERVER_ERROR"] = "server_error";
50
+ ErrorType["TEMPORARILY_UNAVAILABLE"] = "temporarily_unavailable";
51
+ ErrorType["INTERACTION_REQUIRED"] = "interaction_required";
52
+ })(ErrorType = exports.ErrorType || (exports.ErrorType = {}));
53
+ //# sourceMappingURL=consts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consts.js","sourceRoot":"","sources":["../../src/oauthclient/consts.ts"],"names":[],"mappings":";;;AAAA,IAAY,MAkBX;AAlBD,WAAY,MAAM;IACd,iCAAuB,CAAA;IACvB,yCAA+B,CAAA;IAC/B,yCAA+B,CAAA;IAC/B,yBAAe,CAAA;IACf,yBAAe,CAAA;IACf,uCAA6B,CAAA;IAC7B,yBAAe,CAAA;IACf,iDAAuC,CAAA;IACvC,iCAAuB,CAAA;IACvB,mCAAyB,CAAA;IACzB,uBAAa,CAAA;IACb,uCAA6B,CAAA;IAC7B,mCAAyB,CAAA;IACzB,mCAAyB,CAAA;IACzB,+BAAqB,CAAA;IACrB,+BAAqB,CAAA;IACrB,yCAA+B,CAAA;AACnC,CAAC,EAlBW,MAAM,GAAN,cAAM,KAAN,cAAM,QAkBjB;AAED,IAAY,SA2BX;AA3BD,WAAY,SAAS;IACjB,wCAA2B,CAAA;IAC3B,4BAAe,CAAA;IACf,oCAAuB,CAAA;IACvB,gCAAmB,CAAA;IACnB,kDAAqC,CAAA;IACrC,oDAAuC,CAAA;IACvC,oCAAuB,CAAA;IACvB,8CAAiC,CAAA;IACjC,oDAAuC,CAAA;IACvC,gDAAmC,CAAA;IACnC,sDAAyC,CAAA;IACzC,wDAA2C,CAAA;IAC3C,gCAAmB,CAAA;IACnB,0CAA6B,CAAA;IAC7B,4CAA+B,CAAA;IAC/B,kCAAqB,CAAA;IACrB,wCAA2B,CAAA;IAC3B,oCAAuB,CAAA;IACvB,cAAc;IACd,4CAA+B,CAAA;IAC/B,oEAAuD,CAAA;IACvD,4CAA+B,CAAA;IAC/B,4CAA+B,CAAA;IAC/B,0CAA6B,CAAA;IAC7B,gEAAmD,CAAA;IACnD,0DAA6C,CAAA;AACjD,CAAC,EA3BW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QA2BpB"}
@@ -0,0 +1,18 @@
1
+ import { App } from "../app";
2
+ import { Credentials as credentials, ResponseError as responseError } from './models';
3
+ import { AuthClient as authClient, RequestFn as requestFn } from "./interface";
4
+ export { ErrorType } from './consts';
5
+ export interface InitOptions {
6
+ request?: RequestFn;
7
+ retry?: number;
8
+ refreshTokenFunc?: (refreshToken?: string) => Promise<Credentials>;
9
+ tokenInURL?: boolean;
10
+ headers?: {
11
+ [key: string]: string;
12
+ };
13
+ }
14
+ export declare function getOAuthClient(app: App, opts?: InitOptions): authClient;
15
+ export declare type Credentials = credentials;
16
+ export declare type AuthClient = authClient;
17
+ export declare type RequestFn = requestFn;
18
+ export declare type ResponseError = responseError;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getOAuthClient = void 0;
4
+ const internal_1 = require("../app/internal");
5
+ const oauthclient_1 = require("./oauthclient");
6
+ var consts_1 = require("./consts");
7
+ Object.defineProperty(exports, "ErrorType", { enumerable: true, get: function () { return consts_1.ErrorType; } });
8
+ function getOAuthClient(app, opts) {
9
+ return internal_1._getComponent(app, "oauthclient", () => {
10
+ const appOpts = app.options;
11
+ const oauthOpts = {
12
+ clientId: appOpts.clientId,
13
+ clientSecret: appOpts.clientSecret,
14
+ request: appOpts.request,
15
+ storage: appOpts.storage,
16
+ };
17
+ return (new oauthclient_1.OAuth2Client(oauthOpts));
18
+ });
19
+ }
20
+ exports.getOAuthClient = getOAuthClient;
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/oauthclient/index.ts"],"names":[],"mappings":";;;AACA,8CAA8C;AAC9C,+CAA2C;AAG3C,mCAAmC;AAA3B,mGAAA,SAAS,OAAA;AAUjB,SAAgB,cAAc,CAAC,GAAQ,EAAE,IAAkB;IACvD,OAAO,wBAAa,CAAa,GAAG,EAAE,aAAa,EAAE,GAAe,EAAE;QAClE,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAA;QAC3B,MAAM,SAAS,GAAG;YACd,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,YAAY,EAAE,OAAO,CAAC,YAAY;YAClC,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,OAAO,EAAE,OAAO,CAAC,OAAO;SAC3B,CAAA;QACD,OAAO,CAAC,IAAI,0BAAY,CAAC,SAAS,CAAC,CAAC,CAAA;IACxC,CAAC,CAAC,CAAC;AACP,CAAC;AAXD,wCAWC"}
@@ -0,0 +1,25 @@
1
+ import { Credentials, AuthClientRequestOptions } from './models';
2
+ /**
3
+ * the interface for the Oauth2Client
4
+ */
5
+ export declare abstract class AuthClient {
6
+ /**
7
+ * Sets the auth credentials.
8
+ */
9
+ abstract setCredentials(credentials?: Credentials): void;
10
+ /**
11
+ * Provides an alternative fetch api request implementation with auth credentials
12
+ * if options.withCredentials:true, the request will auto add Authorization: Bearer <AccessToken> in the request
13
+ * error:
14
+ * - unreachable, the network error or response is not json
15
+ * - unauthenticated: has no validate access token
16
+ */
17
+ abstract request: RequestFn;
18
+ /**
19
+ * get the current accessToken from AuthClient, you can use this to detect login status
20
+ * error:
21
+ * - unauthenticated: has no validate access token
22
+ */
23
+ abstract getAccessToken(): Promise<string>;
24
+ }
25
+ export declare type RequestFn = <T>(url: string, options?: AuthClientRequestOptions) => Promise<T>;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AuthClient = void 0;
4
+ /**
5
+ * the interface for the Oauth2Client
6
+ */
7
+ class AuthClient {
8
+ }
9
+ exports.AuthClient = AuthClient;
10
+ //# sourceMappingURL=interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interface.js","sourceRoot":"","sources":["../../src/oauthclient/interface.ts"],"names":[],"mappings":";;;AAEA;;GAEG;AACH,MAAsB,UAAU;CAqB/B;AArBD,gCAqBC"}
@@ -1,4 +1,4 @@
1
- import { SimpleStorage } from './interface';
1
+ import { RequestFn, RequestOptions, Storage } from "../app";
2
2
  import { ErrorType } from './consts';
3
3
  export interface Credentials {
4
4
  token_type?: string | null;
@@ -15,30 +15,22 @@ export interface ResponseError {
15
15
  error_uri?: string | null;
16
16
  details?: any | null;
17
17
  }
18
- export interface RequestOptions {
19
- body?: any | null;
20
- headers?: any | null;
21
- method?: string;
22
- [key: string]: any;
23
- }
24
- export declare type RequestFunction = <T>(url: string, options?: RequestOptions) => Promise<T>;
25
18
  export interface AuthClientRequestOptions extends RequestOptions {
26
19
  headers?: {
27
20
  'x-request-id'?: string;
28
21
  [key: string]: any;
29
22
  } | null;
30
23
  withCredentials?: boolean;
24
+ withBasicAuth?: boolean;
31
25
  retry?: number;
32
26
  [key: string]: any;
33
27
  }
34
28
  export interface OAuth2ClientOptions {
35
- devMode?: boolean;
36
- apiOrigin: string;
37
29
  clientId: string;
38
- retry?: number;
39
- baseRequest?: <T>(url: string, options?: RequestOptions) => Promise<T>;
40
- storage?: SimpleStorage;
30
+ storage: Storage;
31
+ request: RequestFn;
41
32
  clientSecret?: string;
33
+ retry?: number;
42
34
  refreshTokenFunc?: (refreshToken?: string) => Promise<Credentials>;
43
35
  tokenInURL?: boolean;
44
36
  headers?: {
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=models.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"models.js","sourceRoot":"","sources":["../../src/oauthclient/models.ts"],"names":[],"mappings":""}