@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.
- package/CHANGELOG.md +30 -0
- package/README.md +137 -5
- package/app/index.d.ts +28 -0
- package/app/index.js +54 -0
- package/app/index.js.map +1 -0
- package/app/internal.d.ts +12 -0
- package/app/internal.js +25 -0
- package/app/internal.js.map +1 -0
- package/app/openuri.d.ts +20 -0
- package/app/openuri.js +104 -0
- package/app/openuri.js.map +1 -0
- package/app/request.d.ts +18 -0
- package/app/request.js +44 -0
- package/app/request.js.map +1 -0
- package/app/storage.d.ts +41 -0
- package/app/storage.js +35 -0
- package/app/storage.js.map +1 -0
- package/{dist/auth → auth}/consts.d.ts +21 -1
- package/auth/consts.js +57 -0
- package/auth/consts.js.map +1 -0
- package/auth/index.d.ts +193 -0
- package/auth/index.js +403 -0
- package/auth/index.js.map +1 -0
- package/{dist/auth → auth}/models.d.ts +35 -25
- package/auth/models.js +3 -0
- package/auth/models.js.map +1 -0
- package/captcha/index.d.ts +45 -0
- package/captcha/index.js +133 -0
- package/captcha/index.js.map +1 -0
- package/index.d.ts +8 -0
- package/index.js +17 -0
- package/index.js.map +1 -0
- package/{dist/oauth2client → oauthclient}/consts.d.ts +1 -22
- package/oauthclient/consts.js +53 -0
- package/oauthclient/consts.js.map +1 -0
- package/oauthclient/index.d.ts +18 -0
- package/oauthclient/index.js +21 -0
- package/oauthclient/index.js.map +1 -0
- package/oauthclient/interface.d.ts +25 -0
- package/oauthclient/interface.js +10 -0
- package/oauthclient/interface.js.map +1 -0
- package/{dist/oauth2client → oauthclient}/models.d.ts +5 -13
- package/oauthclient/models.js +3 -0
- package/oauthclient/models.js.map +1 -0
- package/oauthclient/oauthclient.d.ts +142 -0
- package/oauthclient/oauthclient.js +399 -0
- package/oauthclient/oauthclient.js.map +1 -0
- package/package.json +29 -33
- package/utils/single-promise.d.ts +18 -0
- package/utils/single-promise.js +48 -0
- package/utils/single-promise.js.map +1 -0
- package/utils/uuid.d.ts +5 -0
- package/utils/uuid.js +16 -0
- package/utils/uuid.js.map +1 -0
- package/.eslintignore +0 -2
- package/.eslintrc +0 -26
- package/dist/auth/apis.d.ts +0 -44
- package/dist/auth/apis.js +0 -448
- package/dist/auth/consts.js +0 -35
- package/dist/auth/models.js +0 -3
- package/dist/captcha/captcha.d.ts +0 -35
- package/dist/captcha/captcha.js +0 -262
- package/dist/index.d.ts +0 -9
- package/dist/index.js +0 -234
- package/dist/oauth2client/consts.js +0 -73
- package/dist/oauth2client/interface.d.ts +0 -15
- package/dist/oauth2client/interface.js +0 -10
- package/dist/oauth2client/models.js +0 -3
- package/dist/oauth2client/oauth2client.d.ts +0 -70
- package/dist/oauth2client/oauth2client.js +0 -618
- package/dist/utils/function/single-promise.d.ts +0 -5
- package/dist/utils/function/single-promise.js +0 -89
- package/dist/utils/uuid.d.ts +0 -1
- package/dist/utils/uuid.js +0 -12
- package/src/auth/apis.ts +0 -507
- package/src/auth/consts.ts +0 -30
- package/src/auth/models.ts +0 -178
- package/src/captcha/captcha.ts +0 -217
- package/src/index.ts +0 -162
- package/src/oauth2client/consts.ts +0 -69
- package/src/oauth2client/interface.ts +0 -57
- package/src/oauth2client/models.ts +0 -61
- package/src/oauth2client/oauth2client.ts +0 -606
- package/src/utils/function/single-promise.ts +0 -40
- package/src/utils/uuid.ts +0 -11
- package/tsconfig.json +0 -44
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.SinglePromise = void 0;
|
|
40
|
-
var SinglePromise = (function () {
|
|
41
|
-
function SinglePromise() {
|
|
42
|
-
this._fnPromiseMap = new Map();
|
|
43
|
-
}
|
|
44
|
-
SinglePromise.prototype.run = function (key, fn) {
|
|
45
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
46
|
-
var result;
|
|
47
|
-
var _this = this;
|
|
48
|
-
return __generator(this, function (_a) {
|
|
49
|
-
result = this._fnPromiseMap.get(key);
|
|
50
|
-
if (!result) {
|
|
51
|
-
result = new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
52
|
-
var fnResult, _a, error_1;
|
|
53
|
-
return __generator(this, function (_b) {
|
|
54
|
-
switch (_b.label) {
|
|
55
|
-
case 0:
|
|
56
|
-
_b.trys.push([0, 3, 4, 5]);
|
|
57
|
-
return [4, this._runIdlePromise()];
|
|
58
|
-
case 1:
|
|
59
|
-
_b.sent();
|
|
60
|
-
fnResult = fn();
|
|
61
|
-
_a = resolve;
|
|
62
|
-
return [4, fnResult];
|
|
63
|
-
case 2:
|
|
64
|
-
_a.apply(void 0, [_b.sent()]);
|
|
65
|
-
return [3, 5];
|
|
66
|
-
case 3:
|
|
67
|
-
error_1 = _b.sent();
|
|
68
|
-
reject(error_1);
|
|
69
|
-
return [3, 5];
|
|
70
|
-
case 4:
|
|
71
|
-
this._fnPromiseMap.delete(key);
|
|
72
|
-
return [7];
|
|
73
|
-
case 5: return [2];
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
}); });
|
|
77
|
-
this._fnPromiseMap.set(key, result);
|
|
78
|
-
}
|
|
79
|
-
return [2, result];
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
};
|
|
83
|
-
SinglePromise.prototype._runIdlePromise = function () {
|
|
84
|
-
return Promise.resolve();
|
|
85
|
-
};
|
|
86
|
-
return SinglePromise;
|
|
87
|
-
}());
|
|
88
|
-
exports.SinglePromise = SinglePromise;
|
|
89
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2luZ2xlLXByb21pc2UuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvdXRpbHMvZnVuY3Rpb24vc2luZ2xlLXByb21pc2UudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0FBR0E7SUFBQTtRQW1DVSxrQkFBYSxHQUE4QixJQUFJLEdBQUcsRUFBRSxDQUFDO0lBQy9ELENBQUM7SUE3Qk8sMkJBQUcsR0FBVCxVQUFhLEdBQVcsRUFBRSxFQUFvQjs7Ozs7Z0JBQ3hDLE1BQU0sR0FBaUIsSUFBSSxDQUFDLGFBQWEsQ0FBQyxHQUFHLENBQUMsR0FBRyxDQUFDLENBQUM7Z0JBQ3ZELElBQUksQ0FBQyxNQUFNLEVBQUU7b0JBQ1gsTUFBTSxHQUFHLElBQUksT0FBTyxDQUFNLFVBQU8sT0FBTyxFQUFFLE1BQU07Ozs7OztvQ0FJNUMsV0FBTSxJQUFJLENBQUMsZUFBZSxFQUFFLEVBQUE7O29DQUE1QixTQUE0QixDQUFDO29DQUN2QixRQUFRLEdBQWUsRUFBRSxFQUFFLENBQUM7b0NBQ2xDLEtBQUEsT0FBTyxDQUFBO29DQUFDLFdBQU0sUUFBUSxFQUFBOztvQ0FBdEIsa0JBQVEsU0FBYyxFQUFDLENBQUM7Ozs7b0NBRXhCLE1BQU0sQ0FBQyxPQUFLLENBQUMsQ0FBQzs7O29DQUVkLElBQUksQ0FBQyxhQUFhLENBQUMsTUFBTSxDQUFDLEdBQUcsQ0FBQyxDQ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AgICAgICBjb25zdCBmblJlc3VsdDogUHJvbWlzZTxUPiA9IGZuKCk7XG4gICAgICAgICAgcmVzb2x2ZShhd2FpdCBmblJlc3VsdCk7XG4gICAgICAgIH0gY2F0Y2ggKGVycm9yKSB7XG4gICAgICAgICAgcmVqZWN0KGVycm9yKTtcbiAgICAgICAgfSBmaW5hbGx5IHtcbiAgICAgICAgICB0aGlzLl9mblByb21pc2VNYXAuZGVsZXRlKGtleSk7XG4gICAgICAgIH1cbiAgICAgIH0pO1xuICAgICAgdGhpcy5fZm5Qcm9taXNlTWFwLnNldChrZXksIHJlc3VsdCk7XG4gICAgfVxuICAgIHJldHVybiByZXN1bHQ7XG4gIH1cbiAgLyoqXG4gICAqIFJ1biBpZGxlIHByb21pc2UuXG4gICAqIEByZXR1cm4ge1Byb21pc2U8dm9pZD59XG4gICAqL1xuICBwcml2YXRlIF9ydW5JZGxlUHJvbWlzZSgpOiBQcm9taXNlPHZvaWQ+IHtcbiAgICByZXR1cm4gUHJvbWlzZS5yZXNvbHZlKCk7XG4gIH1cblxuICBwcml2YXRlIF9mblByb21pc2VNYXA6IE1hcDxzdHJpbmcsIFByb21pc2U8YW55Pj4gPSBuZXcgTWFwKCk7XG59XG4iXX0=
|
package/dist/utils/uuid.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function uuidv4(): string;
|
package/dist/utils/uuid.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.uuidv4 = void 0;
|
|
4
|
-
function uuidv4() {
|
|
5
|
-
return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
6
|
-
var r = (Math.random() * 16) | 0;
|
|
7
|
-
var v = c == 'x' ? r : (r & 0x3) | 0x8;
|
|
8
|
-
return v.toString(16);
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
exports.uuid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fQ==
|
package/src/auth/apis.ts
DELETED
|
@@ -1,507 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
import { ApiUrls } from './consts';
|
|
4
|
-
import {
|
|
5
|
-
GetVerificationRequest,
|
|
6
|
-
GetVerificationResponse,
|
|
7
|
-
UserProfile,
|
|
8
|
-
UserInfo,
|
|
9
|
-
SignInRequest,
|
|
10
|
-
SignUpRequest,
|
|
11
|
-
VerifyRequest,
|
|
12
|
-
VerifyResponse,
|
|
13
|
-
GenProviderRedirectUriRequest,
|
|
14
|
-
GenProviderRedirectUriResponse,
|
|
15
|
-
GrantProviderTokenRequest,
|
|
16
|
-
GrantProviderTokenResponse,
|
|
17
|
-
PatchProviderTokenRequest,
|
|
18
|
-
PatchProviderTokenResponse,
|
|
19
|
-
SignInWithProviderRequest,
|
|
20
|
-
BindWithProviderRequest,
|
|
21
|
-
TransByProviderRequest,
|
|
22
|
-
GrantTokenRequest,
|
|
23
|
-
UserProfileProvider,
|
|
24
|
-
UnbindProviderRequest,
|
|
25
|
-
CheckPasswordrRequest,
|
|
26
|
-
BindPhoneRequest,
|
|
27
|
-
SetPasswordRequest,
|
|
28
|
-
ChangeBindedProviderRequest,
|
|
29
|
-
ChangeBindedProviderResponse,
|
|
30
|
-
QueryUserProfileReq,
|
|
31
|
-
} from './models';
|
|
32
|
-
import { SimpleStorage, RequestFunction } from '../oauth2client/interface';
|
|
33
|
-
import { OAuth2Client, defaultStorage } from '../oauth2client/oauth2client';
|
|
34
|
-
import { Credentials } from '../oauth2client/models';
|
|
35
|
-
import { Captcha } from '../captcha/captcha';
|
|
36
|
-
import { ICloudbase } from '@cloudbase/types';
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
export interface AuthOptions {
|
|
40
|
-
apiOrigin: string;
|
|
41
|
-
clientId: string;
|
|
42
|
-
credentialsClient?: OAuth2Client;
|
|
43
|
-
request?: RequestFunction;
|
|
44
|
-
storage?: SimpleStorage;
|
|
45
|
-
_fromApp?: ICloudbase // 所属cloudbase app对象
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Auth
|
|
50
|
-
*/
|
|
51
|
-
export class Auth {
|
|
52
|
-
private _config: AuthOptions;
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* constructor
|
|
56
|
-
* @param {AuthOptions} opts
|
|
57
|
-
*/
|
|
58
|
-
constructor(opts: AuthOptions) {
|
|
59
|
-
let request = opts.request;
|
|
60
|
-
let oAuth2Client = opts.credentialsClient;
|
|
61
|
-
if (!oAuth2Client) {
|
|
62
|
-
const initOptions = {
|
|
63
|
-
apiOrigin: opts.apiOrigin,
|
|
64
|
-
clientId: opts.clientId,
|
|
65
|
-
storage: opts.storage,
|
|
66
|
-
};
|
|
67
|
-
oAuth2Client = new OAuth2Client(initOptions);
|
|
68
|
-
}
|
|
69
|
-
if (!request) {
|
|
70
|
-
const baseRequest = oAuth2Client.request.bind(oAuth2Client);
|
|
71
|
-
const captcha = new Captcha({
|
|
72
|
-
clientId: opts.clientId,
|
|
73
|
-
request: baseRequest,
|
|
74
|
-
storage: opts.storage,
|
|
75
|
-
})
|
|
76
|
-
request = captcha.request.bind(captcha)
|
|
77
|
-
}
|
|
78
|
-
this._config = {
|
|
79
|
-
apiOrigin: opts.apiOrigin,
|
|
80
|
-
clientId: opts.clientId,
|
|
81
|
-
request: request,
|
|
82
|
-
credentialsClient: oAuth2Client,
|
|
83
|
-
storage: opts.storage || defaultStorage,
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Sign in.
|
|
89
|
-
* @param {SignInRequest} params A SignInRequest Object.
|
|
90
|
-
* @return {Promise<Credentials>} A Promise<Credentials> object.
|
|
91
|
-
*/
|
|
92
|
-
public async signIn(params: SignInRequest): Promise<Credentials> {
|
|
93
|
-
params.client_id = this._config.clientId;
|
|
94
|
-
const credentials: Credentials = await this._config.request<Credentials>(
|
|
95
|
-
ApiUrls.AUTH_SIGN_IN_URL,
|
|
96
|
-
{
|
|
97
|
-
method: 'POST',
|
|
98
|
-
body: params
|
|
99
|
-
},
|
|
100
|
-
);
|
|
101
|
-
await this._config.credentialsClient.setCredentials(credentials);
|
|
102
|
-
return Promise.resolve(credentials);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Sign in Anonymously
|
|
107
|
-
* @return {Promise<Credentials>} A Promise<Credentials> object.
|
|
108
|
-
*/
|
|
109
|
-
public async signInAnonymously(): Promise<Credentials> {
|
|
110
|
-
const credentials: Credentials = await this._config.request<Credentials>(
|
|
111
|
-
ApiUrls.AUTH_SIGN_IN_ANONYMOUSLY_URL,
|
|
112
|
-
{
|
|
113
|
-
method: 'POST',
|
|
114
|
-
body: {
|
|
115
|
-
client_id: this._config.clientId
|
|
116
|
-
}
|
|
117
|
-
},
|
|
118
|
-
);
|
|
119
|
-
await this._config.credentialsClient.setCredentials(credentials);
|
|
120
|
-
return Promise.resolve(credentials);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Sign up.
|
|
125
|
-
* @param {SignUpRequest} params A SignUpRequest Object.
|
|
126
|
-
* @return {Promise<Credentials>} A Promise<Credentials> object.
|
|
127
|
-
*/
|
|
128
|
-
protected async signUp(params: SignUpRequest): Promise<Credentials> {
|
|
129
|
-
params.client_id = this._config.clientId;
|
|
130
|
-
const data: Credentials = await this._config.request<Credentials>(
|
|
131
|
-
ApiUrls.AUTH_SIGN_UP_URL,
|
|
132
|
-
{
|
|
133
|
-
method: 'POST',
|
|
134
|
-
body: params,
|
|
135
|
-
},
|
|
136
|
-
);
|
|
137
|
-
await this._config.credentialsClient.setCredentials(data);
|
|
138
|
-
return Promise.resolve(data);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Sign out.
|
|
143
|
-
* @return {Object} A Promise<void> object.
|
|
144
|
-
*/
|
|
145
|
-
public async signOut(): Promise<any> {
|
|
146
|
-
const accessToken: string = await this._config.credentialsClient.getAccessToken();
|
|
147
|
-
const data = await this._config.request(ApiUrls.AUTH_REVOKE_URL, {
|
|
148
|
-
method: 'POST',
|
|
149
|
-
body: {
|
|
150
|
-
client_id: this._config.clientId,
|
|
151
|
-
token: accessToken,
|
|
152
|
-
},
|
|
153
|
-
});
|
|
154
|
-
await this._config.credentialsClient.setCredentials();
|
|
155
|
-
return Promise.resolve(data);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Get the verification.
|
|
160
|
-
* @param {GetVerificationRequest} params A GetVerificationRequest Object.
|
|
161
|
-
* @return {Promise<GetVerificationResponse>} A Promise<GetVerificationResponse> object.
|
|
162
|
-
*/
|
|
163
|
-
public async getVerification(
|
|
164
|
-
params: GetVerificationRequest,
|
|
165
|
-
): Promise<GetVerificationResponse> {
|
|
166
|
-
params.client_id = this._config.clientId;
|
|
167
|
-
return this._config.request<GetVerificationResponse>(
|
|
168
|
-
ApiUrls.VERIFICATION_URL,
|
|
169
|
-
{
|
|
170
|
-
method: 'POST',
|
|
171
|
-
body: params,
|
|
172
|
-
withCaptcha: true
|
|
173
|
-
},
|
|
174
|
-
);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Verify the code
|
|
179
|
-
* @param {VerifyRequest} params A VerifyRequest Object.
|
|
180
|
-
* @return {Promise<VerifyResponse>} A Promise<VerifyResponse> object.
|
|
181
|
-
*/
|
|
182
|
-
public async verify(params: VerifyRequest): Promise<VerifyResponse> {
|
|
183
|
-
params.client_id = this._config.clientId;
|
|
184
|
-
return this._config.request<VerifyResponse>(ApiUrls.VERIFY_URL, {
|
|
185
|
-
method: 'POST',
|
|
186
|
-
body: params,
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* Gen provider redirect uri.
|
|
192
|
-
* @param {GenProviderRedirectUriRequest} params A GenProviderRedirectUriRequest object.
|
|
193
|
-
* @return {Promise<GenProviderRedirectUriResponse>} A Promise<GenProviderRedirectUriResponse> object.
|
|
194
|
-
*/
|
|
195
|
-
public async genProviderRedirectUri(
|
|
196
|
-
params: GenProviderRedirectUriRequest,
|
|
197
|
-
): Promise<GenProviderRedirectUriResponse> {
|
|
198
|
-
let url = `${ApiUrls.PROVIDER_URI_URL}?client_id=${this._config.clientId
|
|
199
|
-
}&provider_id=${params.provider_id}&redirect_uri=${encodeURIComponent(
|
|
200
|
-
params.provider_redirect_uri,
|
|
201
|
-
)}&state=${params.state}`;
|
|
202
|
-
const other_params = params.other_params;
|
|
203
|
-
if (other_params) {
|
|
204
|
-
if (
|
|
205
|
-
typeof other_params.sign_out_uri === 'string' &&
|
|
206
|
-
other_params.sign_out_uri.length > 0
|
|
207
|
-
) {
|
|
208
|
-
url += `&other_params[sign_out_uri]=${other_params.sign_out_uri}`;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
return this._config.request<GenProviderRedirectUriResponse>(url, {
|
|
212
|
-
method: 'GET',
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* Grant provider token.
|
|
218
|
-
* @param {GrantProviderTokenRequest} params A GrantProviderTokenRequest object.
|
|
219
|
-
* @return {Promise<GrantProviderTokenResponse>} A Promise<GrantProviderTokenResponse> object.
|
|
220
|
-
*/
|
|
221
|
-
public async grantProviderToken(
|
|
222
|
-
params: GrantProviderTokenRequest,
|
|
223
|
-
): Promise<GrantProviderTokenResponse> {
|
|
224
|
-
params.client_id = this._config.clientId;
|
|
225
|
-
return this._config.request<GrantProviderTokenResponse>(
|
|
226
|
-
ApiUrls.PROVIDER_TOKEN_URL,
|
|
227
|
-
{
|
|
228
|
-
method: 'POST',
|
|
229
|
-
body: params,
|
|
230
|
-
},
|
|
231
|
-
);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* Grant provider token.
|
|
236
|
-
* @param {PatchProviderTokenRequest} params A PatchProviderTokenRequest object.
|
|
237
|
-
* @return {Promise<PatchProviderTokenResponse>} A Promise<PatchProviderTokenResponse> object.
|
|
238
|
-
*/
|
|
239
|
-
public async patchProviderToken(
|
|
240
|
-
params: PatchProviderTokenRequest,
|
|
241
|
-
): Promise<PatchProviderTokenResponse> {
|
|
242
|
-
params.client_id = this._config.clientId;
|
|
243
|
-
return this._config.request<PatchProviderTokenResponse>(
|
|
244
|
-
ApiUrls.PROVIDER_TOKEN_URL,
|
|
245
|
-
{
|
|
246
|
-
method: 'PATCH',
|
|
247
|
-
body: params,
|
|
248
|
-
},
|
|
249
|
-
);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* Signin with provider request.
|
|
254
|
-
* @param {SignInWithProviderRequest} params A SignInWithProviderRequest object.
|
|
255
|
-
* @return {Promise<Credentials>} A Promise<Credentials> object.
|
|
256
|
-
*/
|
|
257
|
-
public async signInWithProvider(
|
|
258
|
-
params: SignInWithProviderRequest,
|
|
259
|
-
): Promise<Credentials> {
|
|
260
|
-
params.client_id = this._config.clientId;
|
|
261
|
-
const credentials: Credentials = await this._config.request<Credentials>(
|
|
262
|
-
ApiUrls.AUTH_SIGN_IN_WITH_PROVIDER_URL,
|
|
263
|
-
{
|
|
264
|
-
method: 'POST',
|
|
265
|
-
body: params,
|
|
266
|
-
},
|
|
267
|
-
);
|
|
268
|
-
await this._config.credentialsClient.setCredentials(credentials);
|
|
269
|
-
return Promise.resolve(credentials);
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* Bind with provider
|
|
274
|
-
* @param {BindWithProviderRequest} params A BindWithProviderRequest object.
|
|
275
|
-
* @return {Promise<void>} A Promise<any> object.
|
|
276
|
-
*/
|
|
277
|
-
public async bindWithProvider(
|
|
278
|
-
params: BindWithProviderRequest,
|
|
279
|
-
): Promise<void> {
|
|
280
|
-
params.client_id = this._config.clientId;
|
|
281
|
-
return this._config.request<any>(ApiUrls.PROVIDER_BIND_URL, {
|
|
282
|
-
method: 'POST',
|
|
283
|
-
body: params,
|
|
284
|
-
withCredentials: true,
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
/**
|
|
289
|
-
* Get the user profile.
|
|
290
|
-
* @return {Promise<UserProfile>} A Promise<UserProfile> object.
|
|
291
|
-
*/
|
|
292
|
-
public async getUserProfile(): Promise<UserProfile> {
|
|
293
|
-
return this.getUserInfo();
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
/**
|
|
297
|
-
* Get the user info.
|
|
298
|
-
* @return {Promise<UserInfo>} A Promise<UserProfile> object.
|
|
299
|
-
*/
|
|
300
|
-
public async getUserInfo(): Promise<UserInfo> {
|
|
301
|
-
const userInfo = await this._config.request<UserInfo>(ApiUrls.USER_ME_URL, {
|
|
302
|
-
method: 'GET',
|
|
303
|
-
withCredentials: true,
|
|
304
|
-
});
|
|
305
|
-
if (userInfo.picture) {
|
|
306
|
-
userInfo.avatarUrl = userInfo.picture;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
if (userInfo.sub) {
|
|
310
|
-
userInfo.uid = userInfo.sub
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
if (userInfo.name) {
|
|
314
|
-
userInfo.username = userInfo.name
|
|
315
|
-
}
|
|
316
|
-
return userInfo;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
/**
|
|
320
|
-
* hasLoginState check if has login state
|
|
321
|
-
* @return {Promise<boolean>} A Promise<boolean> object.
|
|
322
|
-
*/
|
|
323
|
-
public async hasLoginState(): Promise<boolean> {
|
|
324
|
-
try {
|
|
325
|
-
await this._config.credentialsClient.getAccessToken()
|
|
326
|
-
return true
|
|
327
|
-
} catch (error) {
|
|
328
|
-
return false
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
public hasLoginStateSync(): Credentials | null {
|
|
333
|
-
const credentials = this._config.credentialsClient.getCredentialsSync()
|
|
334
|
-
return credentials
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
public async getLoginState(): Promise<Credentials | null> {
|
|
338
|
-
return this._config.credentialsClient.getCredentialsAsync()
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
/**
|
|
342
|
-
* Trans by provider.
|
|
343
|
-
* @param {TransByProviderRequest} params A TransByProviderRequest object.
|
|
344
|
-
* @return {Promise<Credentials>} A Promise<Credentials> object.
|
|
345
|
-
*/
|
|
346
|
-
public async transByProvider(
|
|
347
|
-
params: TransByProviderRequest,
|
|
348
|
-
): Promise<Credentials> {
|
|
349
|
-
return this._config.request<Credentials>(
|
|
350
|
-
ApiUrls.USER_TRANS_BY_PROVIDER_URL,
|
|
351
|
-
{
|
|
352
|
-
method: 'PATCH',
|
|
353
|
-
body: params,
|
|
354
|
-
withCredentials: true,
|
|
355
|
-
},
|
|
356
|
-
);
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
/**
|
|
360
|
-
* Grant token.
|
|
361
|
-
* @param {GrantTokenRequest} params A GrantTokenRequest object.
|
|
362
|
-
* @return {Promise<Credentials>} A Promise<Credentials> object.
|
|
363
|
-
*/
|
|
364
|
-
public async grantToken(params: GrantTokenRequest): Promise<Credentials> {
|
|
365
|
-
params.client_id = this._config.clientId;
|
|
366
|
-
return this._config.request<Credentials>(ApiUrls.AUTH_TOKEN_URL, {
|
|
367
|
-
method: 'POST',
|
|
368
|
-
body: params,
|
|
369
|
-
});
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
/**
|
|
373
|
-
* Get the provide list.
|
|
374
|
-
* @return {Promise<UserProfileProvider>} A Promise<UserProfileProvider> object.
|
|
375
|
-
*/
|
|
376
|
-
public async getProviders(): Promise<UserProfileProvider> {
|
|
377
|
-
return this._config.request<UserProfileProvider>(ApiUrls.PROVIDER_LIST, {
|
|
378
|
-
method: 'GET',
|
|
379
|
-
withCredentials: true,
|
|
380
|
-
});
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
/**
|
|
384
|
-
* unbind provider.
|
|
385
|
-
* @param {UnbindProviderRequest} params
|
|
386
|
-
* @return {Promise<any>}
|
|
387
|
-
*/
|
|
388
|
-
public async unbindProvider(params: UnbindProviderRequest): Promise<void> {
|
|
389
|
-
params.client_id = this._config.clientId;
|
|
390
|
-
return this._config.request<any>(
|
|
391
|
-
`${ApiUrls.PROVIDER_UNBIND_URL}/${params.provider_id}`,
|
|
392
|
-
{
|
|
393
|
-
method: 'DELETE',
|
|
394
|
-
withCredentials: true,
|
|
395
|
-
},
|
|
396
|
-
);
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
/**
|
|
400
|
-
* check Password.
|
|
401
|
-
* @param {CheckPasswordrRequest} params
|
|
402
|
-
* @return {Promise<any>}
|
|
403
|
-
*/
|
|
404
|
-
public async checkPassword(params: CheckPasswordrRequest): Promise<void> {
|
|
405
|
-
return this._config.request<any>(`${ApiUrls.CHECK_PWD_URL}`, {
|
|
406
|
-
method: 'POST',
|
|
407
|
-
withCredentials: true,
|
|
408
|
-
body: params,
|
|
409
|
-
});
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
/**
|
|
413
|
-
* check Password.
|
|
414
|
-
* @param {CheckPasswordrRequest} params
|
|
415
|
-
* @return {Promise<any>}
|
|
416
|
-
*/
|
|
417
|
-
public async bindPhone(params: BindPhoneRequest): Promise<void> {
|
|
418
|
-
return this._config.request<any>(`${ApiUrls.BIND_PHONE_URL}`, {
|
|
419
|
-
method: 'PATCH',
|
|
420
|
-
withCredentials: true,
|
|
421
|
-
body: params,
|
|
422
|
-
});
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
/**
|
|
426
|
-
* Set Password.
|
|
427
|
-
* @param {SetPasswordrRequest} params
|
|
428
|
-
* @return {Promise<any>}
|
|
429
|
-
*/
|
|
430
|
-
public async setPassword(params: SetPasswordRequest): Promise<void> {
|
|
431
|
-
return this._config.request<any>(`${ApiUrls.AUTH_SET_PASSWORD}`, {
|
|
432
|
-
method: 'PATCH',
|
|
433
|
-
withCredentials: true,
|
|
434
|
-
body: params,
|
|
435
|
-
});
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
/**
|
|
439
|
-
* Get the current user verification.
|
|
440
|
-
* @param {GetVerificationRequest} params A GetVerificationRequest Object.
|
|
441
|
-
* @return {Promise<GetVerificationResponse>} A Promise<GetVerificationResponse> object.
|
|
442
|
-
*/
|
|
443
|
-
public async getCurUserVerification(
|
|
444
|
-
params: GetVerificationRequest,
|
|
445
|
-
): Promise<GetVerificationResponse> {
|
|
446
|
-
params.client_id = this._config.clientId;
|
|
447
|
-
params.target = 'CUR_USER';
|
|
448
|
-
return this._config.request<GetVerificationResponse>(
|
|
449
|
-
ApiUrls.VERIFICATION_URL,
|
|
450
|
-
{
|
|
451
|
-
method: 'POST',
|
|
452
|
-
body: params,
|
|
453
|
-
withCredentials: true,
|
|
454
|
-
withCaptcha: true
|
|
455
|
-
},
|
|
456
|
-
);
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
/**
|
|
460
|
-
* change binded provider.
|
|
461
|
-
* @param {GetVerificationRequest} params A GetVerificationRequest Object.
|
|
462
|
-
* @return {Promise<GetVerificationResponse>} A Promise<GetVerificationResponse> object.
|
|
463
|
-
*/
|
|
464
|
-
public async changeBindedProvider(
|
|
465
|
-
params: ChangeBindedProviderRequest,
|
|
466
|
-
): Promise<ChangeBindedProviderResponse> {
|
|
467
|
-
params.client_id = this._config.clientId;
|
|
468
|
-
return this._config.request<ChangeBindedProviderResponse>(
|
|
469
|
-
`${ApiUrls.PROVIDER_LIST}/${params.provider_id}/trans`,
|
|
470
|
-
{
|
|
471
|
-
method: 'POST',
|
|
472
|
-
body: {
|
|
473
|
-
provider_trans_token: params.trans_token,
|
|
474
|
-
},
|
|
475
|
-
withCredentials: true,
|
|
476
|
-
},
|
|
477
|
-
);
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
/**
|
|
481
|
-
* Patch the user profile.
|
|
482
|
-
* @param {UserProfile} params A UserProfile Object.
|
|
483
|
-
* @return {Promise<UserProfile>} A Promise<UserProfile> object.
|
|
484
|
-
*/
|
|
485
|
-
public async setUserProfile(params: UserProfile): Promise<UserProfile> {
|
|
486
|
-
return this._config.request<UserProfile>(ApiUrls.USER_PRIFILE_URL, {
|
|
487
|
-
method: 'PATCH',
|
|
488
|
-
body: params,
|
|
489
|
-
withCredentials: true,
|
|
490
|
-
});
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
/**
|
|
494
|
-
* Patch the user profile.
|
|
495
|
-
* @param {QueryUserProfileReq} appended_params A QueryUserProfileReq Object.
|
|
496
|
-
* @return {Promise<UserProfile>} A Promise<UserProfile> object.
|
|
497
|
-
*/
|
|
498
|
-
public async queryUserProfile(
|
|
499
|
-
appended_params: QueryUserProfileReq,
|
|
500
|
-
): Promise<UserProfile> {
|
|
501
|
-
const url = `${ApiUrls.USER_QUERY_URL}${appended_params}`;
|
|
502
|
-
return this._config.request<UserProfile>(url, {
|
|
503
|
-
method: 'GET',
|
|
504
|
-
withCredentials: true,
|
|
505
|
-
});
|
|
506
|
-
}
|
|
507
|
-
}
|
package/src/auth/consts.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export enum ApiUrls {
|
|
2
|
-
AUTH_SIGN_IN_URL = '/auth/v1/signin',
|
|
3
|
-
AUTH_SIGN_IN_ANONYMOUSLY_URL = '/auth/v1/signin/anonymously',
|
|
4
|
-
AUTH_SIGN_IN_WITH_PROVIDER_URL = '/auth/v1/signin/with/provider',
|
|
5
|
-
AUTH_SIGN_UP_URL = '/auth/v1/signup',
|
|
6
|
-
AUTH_TOKEN_URL = '/auth/v1/token',
|
|
7
|
-
AUTH_REVOKE_URL = '/auth/v1/revoke',
|
|
8
|
-
PROVIDER_BIND_URL = '/auth/v1/user/provider/bind',
|
|
9
|
-
PROVIDER_TOKEN_URL = '/auth/v1/provider/token',
|
|
10
|
-
PROVIDER_URI_URL = '/auth/v1/provider/uri',
|
|
11
|
-
USER_ME_URL = '/auth/v1/user/me',
|
|
12
|
-
USER_QUERY_URL = '/auth/v1/user/query',
|
|
13
|
-
USER_PRIFILE_URL = '/auth/v1/user/profile',
|
|
14
|
-
USER_TRANS_BY_PROVIDER_URL = '/auth/v1/user/trans/by/provider',
|
|
15
|
-
VERIFICATION_URL = '/auth/v1/verification',
|
|
16
|
-
VERIFY_URL = '/auth/v1/verification/verify',
|
|
17
|
-
PROVIDER_LIST = '/auth/v1/user/provider',
|
|
18
|
-
PROVIDER_UNBIND_URL = '/auth/v1/user/provider',
|
|
19
|
-
CHECK_PWD_URL = '/auth/v1/user/sudo',
|
|
20
|
-
BIND_PHONE_URL = '/auth/v1/user/contact',
|
|
21
|
-
AUTH_SET_PASSWORD = '/auth/v1/user/password',
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export enum VerificationUsages {
|
|
25
|
-
REGISTER = 'REGISTER',
|
|
26
|
-
SIGN_IN = 'SIGN_IN',
|
|
27
|
-
PASSWORD_RESET = 'PASSWORD_RESET',
|
|
28
|
-
EMAIL_ADDRESS_CHANGE = 'EMAIL_ADDRESS_CHANGE',
|
|
29
|
-
PHONE_NUMBER_CHANGE = 'PHONE_NUMBER_CHANGE',
|
|
30
|
-
}
|