@mspkapps/auth-client 0.1.23 → 0.1.25
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/package.json +1 -1
- package/src/AuthClient.js +19 -3
package/package.json
CHANGED
package/src/AuthClient.js
CHANGED
|
@@ -94,8 +94,8 @@ export class AuthClient {
|
|
|
94
94
|
return json;
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
async googleAuth({ id_token
|
|
98
|
-
if (!id_token
|
|
97
|
+
async googleAuth({ id_token }) {
|
|
98
|
+
if (!id_token) {
|
|
99
99
|
throw new AuthError(
|
|
100
100
|
'Either id_token or access_token is required for Google authentication',
|
|
101
101
|
400,
|
|
@@ -105,7 +105,7 @@ export class AuthClient {
|
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
// include googleClientId in body too (helpful if backend needs it)
|
|
108
|
-
const body = { id_token
|
|
108
|
+
const body = { id_token };
|
|
109
109
|
if (this.googleClientId) body.google_client_id = this.googleClientId;
|
|
110
110
|
|
|
111
111
|
const resp = await this.fetch(this._buildUrl('auth/google'), {
|
|
@@ -209,6 +209,19 @@ export class AuthClient {
|
|
|
209
209
|
return json;
|
|
210
210
|
}
|
|
211
211
|
|
|
212
|
+
async verifyToken(accessToken) {
|
|
213
|
+
const resp = await this.fetch(this._buildUrl('auth/verify-token'), {
|
|
214
|
+
method: 'POST',
|
|
215
|
+
headers: {
|
|
216
|
+
...this._headers(),
|
|
217
|
+
Authorization: `Bearer ${accessToken}`
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
const json = await safeJson(resp);
|
|
221
|
+
if (!resp.ok || json?.success === false) throw toError(resp, json, 'Verify token failed');
|
|
222
|
+
return json?.data ?? json;
|
|
223
|
+
}
|
|
224
|
+
|
|
212
225
|
async authed(path, { method = 'GET', body, headers } = {}) {
|
|
213
226
|
const resp = await this.fetch(this._buildUrl(path), {
|
|
214
227
|
method,
|
|
@@ -308,6 +321,9 @@ const authclient = {
|
|
|
308
321
|
logout() {
|
|
309
322
|
return ensureClient().logout();
|
|
310
323
|
},
|
|
324
|
+
verifyToken(accessToken) {
|
|
325
|
+
return ensureClient().verifyToken(accessToken);
|
|
326
|
+
},
|
|
311
327
|
};
|
|
312
328
|
|
|
313
329
|
export { authclient, init }; // named exports if someone prefers them
|