@shware/security 2.5.3 → 3.0.0
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/auth/index.cjs +519 -561
- package/dist/auth/index.cjs.map +1 -1
- package/dist/auth/index.d.cts +104 -106
- package/dist/auth/index.d.cts.map +1 -0
- package/dist/auth/index.d.mts +109 -0
- package/dist/auth/index.d.mts.map +1 -0
- package/dist/auth/index.mjs +512 -536
- package/dist/auth/index.mjs.map +1 -1
- package/dist/auth/types.cjs +0 -19
- package/dist/auth/types.d.cts +44 -44
- package/dist/auth/types.d.cts.map +1 -0
- package/dist/auth/types.d.mts +50 -0
- package/dist/auth/types.d.mts.map +1 -0
- package/dist/auth/types.mjs +1 -1
- package/dist/core/index.cjs +18 -59
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +13 -24
- package/dist/core/index.d.cts.map +1 -0
- package/dist/core/index.d.mts +21 -0
- package/dist/core/index.d.mts.map +1 -0
- package/dist/core/index.mjs +17 -33
- package/dist/core/index.mjs.map +1 -1
- package/dist/email/schema.cjs +13 -38
- package/dist/email/schema.cjs.map +1 -1
- package/dist/email/schema.d.cts +11 -12
- package/dist/email/schema.d.cts.map +1 -0
- package/dist/email/schema.d.mts +12 -0
- package/dist/email/schema.d.mts.map +1 -0
- package/dist/email/schema.mjs +10 -11
- package/dist/email/schema.mjs.map +1 -1
- package/dist/index.cjs +18 -54
- package/dist/index.d.cts +10 -15
- package/dist/index.d.mts +10 -0
- package/dist/index.mjs +5 -17
- package/dist/oauth2/client.cjs +109 -145
- package/dist/oauth2/client.cjs.map +1 -1
- package/dist/oauth2/client.d.cts +55 -56
- package/dist/oauth2/client.d.cts.map +1 -0
- package/dist/oauth2/client.d.mts +58 -0
- package/dist/oauth2/client.d.mts.map +1 -0
- package/dist/oauth2/client.mjs +104 -116
- package/dist/oauth2/client.mjs.map +1 -1
- package/dist/oauth2/error.cjs +19 -44
- package/dist/oauth2/error.cjs.map +1 -1
- package/dist/oauth2/error.d.cts +8 -6
- package/dist/oauth2/error.d.cts.map +1 -0
- package/dist/oauth2/{error.d.ts → error.d.mts} +8 -6
- package/dist/oauth2/error.d.mts.map +1 -0
- package/dist/oauth2/error.mjs +18 -19
- package/dist/oauth2/error.mjs.map +1 -1
- package/dist/oauth2/provider/apple.cjs +75 -88
- package/dist/oauth2/provider/apple.cjs.map +1 -1
- package/dist/oauth2/provider/apple.d.cts +31 -30
- package/dist/oauth2/provider/apple.d.cts.map +1 -0
- package/dist/oauth2/provider/apple.d.mts +42 -0
- package/dist/oauth2/provider/apple.d.mts.map +1 -0
- package/dist/oauth2/provider/apple.mjs +71 -60
- package/dist/oauth2/provider/apple.mjs.map +1 -1
- package/dist/oauth2/provider/common.cjs +86 -109
- package/dist/oauth2/provider/common.cjs.map +1 -1
- package/dist/oauth2/provider/common.d.cts +19 -18
- package/dist/oauth2/provider/common.d.cts.map +1 -0
- package/dist/oauth2/provider/common.d.mts +30 -0
- package/dist/oauth2/provider/common.d.mts.map +1 -0
- package/dist/oauth2/provider/common.mjs +80 -79
- package/dist/oauth2/provider/common.mjs.map +1 -1
- package/dist/oauth2/provider/facebook.cjs +93 -109
- package/dist/oauth2/provider/facebook.cjs.map +1 -1
- package/dist/oauth2/provider/facebook.d.cts +29 -28
- package/dist/oauth2/provider/facebook.d.cts.map +1 -0
- package/dist/oauth2/provider/facebook.d.mts +45 -0
- package/dist/oauth2/provider/facebook.d.mts.map +1 -0
- package/dist/oauth2/provider/facebook.mjs +89 -81
- package/dist/oauth2/provider/facebook.mjs.map +1 -1
- package/dist/oauth2/provider/github.cjs +64 -91
- package/dist/oauth2/provider/github.cjs.map +1 -1
- package/dist/oauth2/provider/github.d.cts +52 -51
- package/dist/oauth2/provider/github.d.cts.map +1 -0
- package/dist/oauth2/provider/github.d.mts +60 -0
- package/dist/oauth2/provider/github.d.mts.map +1 -0
- package/dist/oauth2/provider/github.mjs +60 -63
- package/dist/oauth2/provider/github.mjs.map +1 -1
- package/dist/oauth2/provider/google.cjs +105 -122
- package/dist/oauth2/provider/google.cjs.map +1 -1
- package/dist/oauth2/provider/google.d.cts +34 -33
- package/dist/oauth2/provider/google.d.cts.map +1 -0
- package/dist/oauth2/provider/google.d.mts +44 -0
- package/dist/oauth2/provider/google.d.mts.map +1 -0
- package/dist/oauth2/provider/google.mjs +101 -94
- package/dist/oauth2/provider/google.mjs.map +1 -1
- package/dist/oauth2/provider/index.cjs +13 -46
- package/dist/oauth2/provider/index.d.cts +7 -7
- package/dist/oauth2/provider/index.d.mts +7 -0
- package/dist/oauth2/provider/index.mjs +1 -10
- package/dist/oauth2/provider/wechat.cjs +77 -99
- package/dist/oauth2/provider/wechat.cjs.map +1 -1
- package/dist/oauth2/provider/wechat.d.cts +28 -27
- package/dist/oauth2/provider/wechat.d.cts.map +1 -0
- package/dist/oauth2/provider/wechat.d.mts +39 -0
- package/dist/oauth2/provider/wechat.d.mts.map +1 -0
- package/dist/oauth2/provider/wechat.mjs +74 -72
- package/dist/oauth2/provider/wechat.mjs.map +1 -1
- package/dist/oauth2/provider/x.cjs +102 -125
- package/dist/oauth2/provider/x.cjs.map +1 -1
- package/dist/oauth2/provider/x.d.cts +51 -50
- package/dist/oauth2/provider/x.d.cts.map +1 -0
- package/dist/oauth2/provider/x.d.mts +69 -0
- package/dist/oauth2/provider/x.d.mts.map +1 -0
- package/dist/oauth2/provider/x.mjs +99 -103
- package/dist/oauth2/provider/x.mjs.map +1 -1
- package/dist/oauth2/types.cjs +12 -37
- package/dist/oauth2/types.cjs.map +1 -1
- package/dist/oauth2/types.d.cts +176 -180
- package/dist/oauth2/types.d.cts.map +1 -0
- package/dist/oauth2/types.d.mts +207 -0
- package/dist/oauth2/types.d.mts.map +1 -0
- package/dist/oauth2/types.mjs +12 -13
- package/dist/oauth2/types.mjs.map +1 -1
- package/dist/session/common.cjs +17 -43
- package/dist/session/common.cjs.map +1 -1
- package/dist/session/common.d.cts +4 -4
- package/dist/session/common.d.cts.map +1 -0
- package/dist/session/{common.d.ts → common.d.mts} +4 -4
- package/dist/session/common.d.mts.map +1 -0
- package/dist/session/common.mjs +14 -16
- package/dist/session/common.mjs.map +1 -1
- package/dist/session/db.cjs +88 -123
- package/dist/session/db.cjs.map +1 -1
- package/dist/session/db.d.cts +36 -36
- package/dist/session/db.d.cts.map +1 -0
- package/dist/session/db.d.mts +44 -0
- package/dist/session/db.d.mts.map +1 -0
- package/dist/session/db.mjs +84 -95
- package/dist/session/db.mjs.map +1 -1
- package/dist/session/map-session.cjs +71 -103
- package/dist/session/map-session.cjs.map +1 -1
- package/dist/session/map-session.d.cts +24 -24
- package/dist/session/map-session.d.cts.map +1 -0
- package/dist/session/map-session.d.mts +27 -0
- package/dist/session/map-session.d.mts.map +1 -0
- package/dist/session/map-session.mjs +70 -78
- package/dist/session/map-session.mjs.map +1 -1
- package/dist/session/redis.cjs +270 -319
- package/dist/session/redis.cjs.map +1 -1
- package/dist/session/redis.d.cts +51 -51
- package/dist/session/redis.d.cts.map +1 -0
- package/dist/session/redis.d.mts +58 -0
- package/dist/session/redis.d.mts.map +1 -0
- package/dist/session/redis.mjs +266 -291
- package/dist/session/redis.mjs.map +1 -1
- package/dist/session/types.cjs +0 -19
- package/dist/session/types.d.cts +34 -33
- package/dist/session/types.d.cts.map +1 -0
- package/dist/session/types.d.mts +45 -0
- package/dist/session/types.d.mts.map +1 -0
- package/dist/session/types.mjs +1 -1
- package/dist/utils/http.cjs +31 -55
- package/dist/utils/http.cjs.map +1 -1
- package/dist/utils/http.d.cts +7 -10
- package/dist/utils/http.d.cts.map +1 -0
- package/dist/utils/{http.d.ts → http.d.mts} +7 -10
- package/dist/utils/http.d.mts.map +1 -0
- package/dist/utils/http.mjs +24 -24
- package/dist/utils/http.mjs.map +1 -1
- package/dist/utils/oauth2.cjs +6 -30
- package/dist/utils/oauth2.cjs.map +1 -1
- package/dist/utils/oauth2.d.cts +3 -1
- package/dist/utils/oauth2.d.cts.map +1 -0
- package/dist/utils/oauth2.d.mts +5 -0
- package/dist/utils/oauth2.d.mts.map +1 -0
- package/dist/utils/oauth2.mjs +5 -5
- package/dist/utils/oauth2.mjs.map +1 -1
- package/dist/utils/timing.cjs +49 -70
- package/dist/utils/timing.cjs.map +1 -1
- package/dist/utils/timing.d.cts +10 -8
- package/dist/utils/timing.d.cts.map +1 -0
- package/dist/utils/timing.d.mts +15 -0
- package/dist/utils/timing.d.mts.map +1 -0
- package/dist/utils/timing.mjs +48 -45
- package/dist/utils/timing.mjs.map +1 -1
- package/dist/utils/valid.cjs +50 -71
- package/dist/utils/valid.cjs.map +1 -1
- package/dist/utils/valid.d.cts +17 -16
- package/dist/utils/valid.d.cts.map +1 -0
- package/dist/utils/valid.d.mts +28 -0
- package/dist/utils/valid.d.mts.map +1 -0
- package/dist/utils/valid.mjs +47 -44
- package/dist/utils/valid.mjs.map +1 -1
- package/package.json +22 -12
- package/dist/auth/index.d.ts +0 -111
- package/dist/auth/types.cjs.map +0 -1
- package/dist/auth/types.d.ts +0 -50
- package/dist/auth/types.mjs.map +0 -1
- package/dist/core/index.d.ts +0 -32
- package/dist/email/schema.d.ts +0 -13
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.ts +0 -15
- package/dist/index.mjs.map +0 -1
- package/dist/oauth2/client.d.ts +0 -59
- package/dist/oauth2/provider/apple.d.ts +0 -41
- package/dist/oauth2/provider/common.d.ts +0 -29
- package/dist/oauth2/provider/facebook.d.ts +0 -44
- package/dist/oauth2/provider/github.d.ts +0 -59
- package/dist/oauth2/provider/google.d.ts +0 -43
- package/dist/oauth2/provider/index.cjs.map +0 -1
- package/dist/oauth2/provider/index.d.ts +0 -7
- package/dist/oauth2/provider/index.mjs.map +0 -1
- package/dist/oauth2/provider/wechat.d.ts +0 -38
- package/dist/oauth2/provider/x.d.ts +0 -68
- package/dist/oauth2/types.d.ts +0 -211
- package/dist/session/__tests__/redis.test.cjs +0 -247
- package/dist/session/__tests__/redis.test.cjs.map +0 -1
- package/dist/session/__tests__/redis.test.d.cts +0 -2
- package/dist/session/__tests__/redis.test.d.ts +0 -2
- package/dist/session/__tests__/redis.test.mjs +0 -252
- package/dist/session/__tests__/redis.test.mjs.map +0 -1
- package/dist/session/db.d.ts +0 -44
- package/dist/session/map-session.d.ts +0 -27
- package/dist/session/redis.d.ts +0 -58
- package/dist/session/types.cjs.map +0 -1
- package/dist/session/types.d.ts +0 -44
- package/dist/session/types.mjs.map +0 -1
- package/dist/utils/oauth2.d.ts +0 -3
- package/dist/utils/timing.d.ts +0 -13
- package/dist/utils/valid.d.ts +0 -27
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/oauth2/error.ts"],"sourcesContent":["// reference: https://datatracker.ietf.org/doc/html/rfc6749#section-4.2.2.1\nexport type OAuth2ErrorType =\n | 'invalid_request' // 400\n | 'invalid_client' // 401\n | 'invalid_grant' // 400\n | 'invalid_token' // 401\n | 'invalid_scope' // 400\n | 'unauthorized_client' // 401\n | 'unsupported_grant_type' // 400\n | 'unsupported_response_type' // 400\n | 'insufficient_scope' // 403\n | 'redirect_uri_mismatch' // 400\n | 'access_denied' // 400\n | 'server_error' // 500\n | 'temporarily_unavailable' // 503\n | (string & {});\n\nexport class OAuth2Error extends Error {\n readonly status: number;\n readonly error: OAuth2ErrorType;\n\n constructor(status: number, error: OAuth2ErrorType, message?: string) {\n super(message ?? `OAuth2 error: ${error}`);\n this.status = status;\n this.error = error;\n Object.setPrototypeOf(this, OAuth2Error.prototype);\n }\n}\n\nexport class AuthenticationError extends Error {\n constructor(message: string) {\n super(message);\n Object.setPrototypeOf(this, AuthenticationError.prototype);\n }\n}\n"],"mappings":";
|
|
1
|
+
{"version":3,"file":"error.mjs","names":[],"sources":["../../src/oauth2/error.ts"],"sourcesContent":["// reference: https://datatracker.ietf.org/doc/html/rfc6749#section-4.2.2.1\nexport type OAuth2ErrorType =\n | 'invalid_request' // 400\n | 'invalid_client' // 401\n | 'invalid_grant' // 400\n | 'invalid_token' // 401\n | 'invalid_scope' // 400\n | 'unauthorized_client' // 401\n | 'unsupported_grant_type' // 400\n | 'unsupported_response_type' // 400\n | 'insufficient_scope' // 403\n | 'redirect_uri_mismatch' // 400\n | 'access_denied' // 400\n | 'server_error' // 500\n | 'temporarily_unavailable' // 503\n | (string & {});\n\nexport class OAuth2Error extends Error {\n readonly status: number;\n readonly error: OAuth2ErrorType;\n\n constructor(status: number, error: OAuth2ErrorType, message?: string) {\n super(message ?? `OAuth2 error: ${error}`);\n this.status = status;\n this.error = error;\n Object.setPrototypeOf(this, OAuth2Error.prototype);\n }\n}\n\nexport class AuthenticationError extends Error {\n constructor(message: string) {\n super(message);\n Object.setPrototypeOf(this, AuthenticationError.prototype);\n }\n}\n"],"mappings":";AAiBA,IAAa,cAAb,MAAa,oBAAoB,MAAM;CACrC;CACA;CAEA,YAAY,QAAgB,OAAwB,SAAkB;EACpE,MAAM,WAAW,iBAAiB,OAAO;EACzC,KAAK,SAAS;EACd,KAAK,QAAQ;EACb,OAAO,eAAe,MAAM,YAAY,SAAS;CACnD;AACF;AAEA,IAAa,sBAAb,MAAa,4BAA4B,MAAM;CAC7C,YAAY,SAAiB;EAC3B,MAAM,OAAO;EACb,OAAO,eAAe,MAAM,oBAAoB,SAAS;CAC3D;AACF"}
|
|
@@ -1,91 +1,78 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/oauth2/provider/apple.ts
|
|
21
|
-
var apple_exports = {};
|
|
22
|
-
__export(apple_exports, {
|
|
23
|
-
apple: () => apple,
|
|
24
|
-
createAppleProvider: () => createAppleProvider
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(apple_exports);
|
|
27
|
-
var import_utils = require("@shware/utils");
|
|
28
|
-
var import_error = require("../error.cjs");
|
|
29
|
-
var import_common = require("./common.cjs");
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_oauth2_error = require("../error.cjs");
|
|
3
|
+
const require_oauth2_provider_common = require("./common.cjs");
|
|
4
|
+
let _shware_utils = require("@shware/utils");
|
|
5
|
+
//#region src/oauth2/provider/apple.ts
|
|
30
6
|
function createAppleProvider() {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
7
|
+
return {
|
|
8
|
+
authorizationUri: "https://appleid.apple.com/auth/authorize?response_mode=form_post",
|
|
9
|
+
tokenUri: "https://appleid.apple.com/auth/token",
|
|
10
|
+
jwkSetUri: "https://appleid.apple.com/auth/keys",
|
|
11
|
+
userNameAttribute: "sub",
|
|
12
|
+
defaultScope: [
|
|
13
|
+
"openid",
|
|
14
|
+
"name",
|
|
15
|
+
"email"
|
|
16
|
+
],
|
|
17
|
+
createAuthorizationUri({ pkce: _, ...params }) {
|
|
18
|
+
return require_oauth2_provider_common.createAuthorizationUri({
|
|
19
|
+
...params,
|
|
20
|
+
scope: params.scope ?? this.defaultScope,
|
|
21
|
+
authorizationUri: this.authorizationUri
|
|
22
|
+
});
|
|
23
|
+
},
|
|
24
|
+
async exchangeAuthorizationCode({ pkce: _, ...params }) {
|
|
25
|
+
const response = await require_oauth2_provider_common.exchangeAuthorizationCode({
|
|
26
|
+
...params,
|
|
27
|
+
tokenUri: this.tokenUri
|
|
28
|
+
});
|
|
29
|
+
if (!response.ok) {
|
|
30
|
+
const { error } = await response.json();
|
|
31
|
+
throw new require_oauth2_error.OAuth2Error(response.status, error);
|
|
32
|
+
}
|
|
33
|
+
return await response.json();
|
|
34
|
+
},
|
|
35
|
+
async getUserInfo({ id_token }) {
|
|
36
|
+
(0, _shware_utils.invariant)(id_token, "id_token is required");
|
|
37
|
+
(0, _shware_utils.invariant)(this.jwkSetUri, "jwkSetUri is required");
|
|
38
|
+
const data = await require_oauth2_provider_common.verifyIdToken(id_token, this.jwkSetUri);
|
|
39
|
+
return {
|
|
40
|
+
data,
|
|
41
|
+
claims: {
|
|
42
|
+
sub: data.sub,
|
|
43
|
+
name: data.name,
|
|
44
|
+
email: data.email,
|
|
45
|
+
email_verified: true,
|
|
46
|
+
picture: data.picture,
|
|
47
|
+
given_name: data.user?.name.firstName,
|
|
48
|
+
family_name: data.user?.name.lastName
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
async loginOAuth2Native({ pkce: _, credentials, ...params }) {
|
|
53
|
+
(0, _shware_utils.invariant)(credentials.code, "code is required");
|
|
54
|
+
const { tokenUri } = this;
|
|
55
|
+
const { code } = credentials;
|
|
56
|
+
const response = await require_oauth2_provider_common.exchangeAuthorizationCode({
|
|
57
|
+
code,
|
|
58
|
+
tokenUri,
|
|
59
|
+
...params
|
|
60
|
+
});
|
|
61
|
+
if (!response.ok) {
|
|
62
|
+
const { error } = await response.json();
|
|
63
|
+
throw new require_oauth2_error.OAuth2Error(response.status, error);
|
|
64
|
+
}
|
|
65
|
+
const token = await response.json();
|
|
66
|
+
return {
|
|
67
|
+
token,
|
|
68
|
+
userInfo: await this.getUserInfo(token)
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
};
|
|
84
72
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
});
|
|
73
|
+
const apple = createAppleProvider();
|
|
74
|
+
//#endregion
|
|
75
|
+
exports.apple = apple;
|
|
76
|
+
exports.createAppleProvider = createAppleProvider;
|
|
77
|
+
|
|
91
78
|
//# sourceMappingURL=apple.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/oauth2/provider/apple.ts"],"sourcesContent":["import { invariant } from '@shware/utils';\nimport { OAuth2Error } from '../error';\nimport type { LoginOAuth2NativeParams, NativeCredential, OAuth2Token, Provider } from '../types';\nimport { createAuthorizationUri, exchangeAuthorizationCode, verifyIdToken } from './common';\n\n// ref: https://account.apple.com/.well-known/openid-configuration\nexport function createAppleProvider(): Provider {\n return {\n // important notice: response_mode=form_post is required for apple\n authorizationUri: 'https://appleid.apple.com/auth/authorize?response_mode=form_post',\n tokenUri: 'https://appleid.apple.com/auth/token',\n jwkSetUri: 'https://appleid.apple.com/auth/keys',\n userNameAttribute: 'sub',\n defaultScope: ['openid', 'name', 'email'],\n createAuthorizationUri({ pkce: _, ...params }) {\n return createAuthorizationUri({\n ...params,\n scope: params.scope ?? this.defaultScope,\n authorizationUri: this.authorizationUri,\n });\n },\n async exchangeAuthorizationCode({ pkce: _, ...params }) {\n const response = await exchangeAuthorizationCode({ ...params, tokenUri: this.tokenUri });\n if (!response.ok) {\n const { error } = (await response.json()) as AppleErrorResponse;\n throw new OAuth2Error(response.status, error);\n }\n return (await response.json()) as AppleToken;\n },\n async getUserInfo({ id_token }) {\n invariant(id_token, 'id_token is required');\n invariant(this.jwkSetUri, 'jwkSetUri is required');\n const data = await verifyIdToken<AppleUserInfo>(id_token, this.jwkSetUri);\n return {\n data,\n claims: {\n sub: data.sub,\n name: data.name,\n email: data.email,\n email_verified: true,\n picture: data.picture,\n given_name: data.user?.name.firstName,\n family_name: data.user?.name.lastName,\n },\n };\n },\n async loginOAuth2Native({ pkce: _, credentials, ...params }: LoginOAuth2NativeParams) {\n invariant(credentials.code, 'code is required');\n const { tokenUri } = this;\n const { code } = credentials;\n const response = await exchangeAuthorizationCode({ code, tokenUri, ...params });\n if (!response.ok) {\n const { error } = (await response.json()) as AppleErrorResponse;\n throw new OAuth2Error(response.status, error);\n }\n const token = (await response.json()) as AppleToken;\n const userInfo = await this.getUserInfo(token);\n return { token, userInfo };\n },\n };\n}\n\nexport const apple = createAppleProvider();\n\n// https://developer.apple.com/documentation/sign_in_with_apple/authenticating-users-with-sign-in-with-apple\nexport interface AppleUserInfo {\n sub: string;\n email: string;\n email_verified: true | 'true';\n is_private_email: boolean;\n real_user_status: number;\n name: string;\n picture: string;\n user?: {\n name: { firstName: string; lastName: string };\n email: string;\n };\n nonce?: string;\n nonce_supported?: boolean;\n}\n\n// https://developer.apple.com/documentation/devicemanagement/implementing-the-oauth2-authentication-user-enrollment-flow\n// https://developer.apple.com/documentation/sign_in_with_apple/generate_and_validate_tokens\nexport interface AppleToken extends OAuth2Token {\n access_token: string;\n token_type: string;\n expires_in: number;\n refresh_token: string;\n id_token: string;\n}\n\nexport interface AppleNativeCredential extends NativeCredential {\n state: string;\n code: string;\n id_token: string;\n // no standard fields\n user: string;\n email?: string;\n}\n\n// https://developer.apple.com/documentation/sign_in_with_apple/errorresponse\nexport interface AppleErrorResponse {\n error:\n | 'invalid_request'\n | 'invalid_client'\n | 'invalid_grant'\n | 'unauthorized_client'\n | 'unsupported_grant_type'\n | 'invalid_scope';\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"apple.cjs","names":["createAuthorizationUri","exchangeAuthorizationCode","OAuth2Error","verifyIdToken"],"sources":["../../../src/oauth2/provider/apple.ts"],"sourcesContent":["import { invariant } from '@shware/utils';\nimport { OAuth2Error } from '../error';\nimport type { LoginOAuth2NativeParams, NativeCredential, OAuth2Token, Provider } from '../types';\nimport { createAuthorizationUri, exchangeAuthorizationCode, verifyIdToken } from './common';\n\n// ref: https://account.apple.com/.well-known/openid-configuration\nexport function createAppleProvider(): Provider {\n return {\n // important notice: response_mode=form_post is required for apple\n authorizationUri: 'https://appleid.apple.com/auth/authorize?response_mode=form_post',\n tokenUri: 'https://appleid.apple.com/auth/token',\n jwkSetUri: 'https://appleid.apple.com/auth/keys',\n userNameAttribute: 'sub',\n defaultScope: ['openid', 'name', 'email'],\n createAuthorizationUri({ pkce: _, ...params }) {\n return createAuthorizationUri({\n ...params,\n scope: params.scope ?? this.defaultScope,\n authorizationUri: this.authorizationUri,\n });\n },\n async exchangeAuthorizationCode({ pkce: _, ...params }) {\n const response = await exchangeAuthorizationCode({ ...params, tokenUri: this.tokenUri });\n if (!response.ok) {\n const { error } = (await response.json()) as AppleErrorResponse;\n throw new OAuth2Error(response.status, error);\n }\n return (await response.json()) as AppleToken;\n },\n async getUserInfo({ id_token }) {\n invariant(id_token, 'id_token is required');\n invariant(this.jwkSetUri, 'jwkSetUri is required');\n const data = await verifyIdToken<AppleUserInfo>(id_token, this.jwkSetUri);\n return {\n data,\n claims: {\n sub: data.sub,\n name: data.name,\n email: data.email,\n email_verified: true,\n picture: data.picture,\n given_name: data.user?.name.firstName,\n family_name: data.user?.name.lastName,\n },\n };\n },\n async loginOAuth2Native({ pkce: _, credentials, ...params }: LoginOAuth2NativeParams) {\n invariant(credentials.code, 'code is required');\n const { tokenUri } = this;\n const { code } = credentials;\n const response = await exchangeAuthorizationCode({ code, tokenUri, ...params });\n if (!response.ok) {\n const { error } = (await response.json()) as AppleErrorResponse;\n throw new OAuth2Error(response.status, error);\n }\n const token = (await response.json()) as AppleToken;\n const userInfo = await this.getUserInfo(token);\n return { token, userInfo };\n },\n };\n}\n\nexport const apple = createAppleProvider();\n\n// https://developer.apple.com/documentation/sign_in_with_apple/authenticating-users-with-sign-in-with-apple\nexport interface AppleUserInfo {\n sub: string;\n email: string;\n email_verified: true | 'true';\n is_private_email: boolean;\n real_user_status: number;\n name: string;\n picture: string;\n user?: {\n name: { firstName: string; lastName: string };\n email: string;\n };\n nonce?: string;\n nonce_supported?: boolean;\n}\n\n// https://developer.apple.com/documentation/devicemanagement/implementing-the-oauth2-authentication-user-enrollment-flow\n// https://developer.apple.com/documentation/sign_in_with_apple/generate_and_validate_tokens\nexport interface AppleToken extends OAuth2Token {\n access_token: string;\n token_type: string;\n expires_in: number;\n refresh_token: string;\n id_token: string;\n}\n\nexport interface AppleNativeCredential extends NativeCredential {\n state: string;\n code: string;\n id_token: string;\n // no standard fields\n user: string;\n email?: string;\n}\n\n// https://developer.apple.com/documentation/sign_in_with_apple/errorresponse\nexport interface AppleErrorResponse {\n error:\n | 'invalid_request'\n | 'invalid_client'\n | 'invalid_grant'\n | 'unauthorized_client'\n | 'unsupported_grant_type'\n | 'invalid_scope';\n}\n"],"mappings":";;;;;AAMA,SAAgB,sBAAgC;CAC9C,OAAO;EAEL,kBAAkB;EAClB,UAAU;EACV,WAAW;EACX,mBAAmB;EACnB,cAAc;GAAC;GAAU;GAAQ;EAAO;EACxC,uBAAuB,EAAE,MAAM,GAAG,GAAG,UAAU;GAC7C,OAAOA,+BAAAA,uBAAuB;IAC5B,GAAG;IACH,OAAO,OAAO,SAAS,KAAK;IAC5B,kBAAkB,KAAK;GACzB,CAAC;EACH;EACA,MAAM,0BAA0B,EAAE,MAAM,GAAG,GAAG,UAAU;GACtD,MAAM,WAAW,MAAMC,+BAAAA,0BAA0B;IAAE,GAAG;IAAQ,UAAU,KAAK;GAAS,CAAC;GACvF,IAAI,CAAC,SAAS,IAAI;IAChB,MAAM,EAAE,UAAW,MAAM,SAAS,KAAK;IACvC,MAAM,IAAIC,qBAAAA,YAAY,SAAS,QAAQ,KAAK;GAC9C;GACA,OAAQ,MAAM,SAAS,KAAK;EAC9B;EACA,MAAM,YAAY,EAAE,YAAY;GAC9B,CAAA,GAAA,cAAA,UAAA,CAAU,UAAU,sBAAsB;GAC1C,CAAA,GAAA,cAAA,UAAA,CAAU,KAAK,WAAW,uBAAuB;GACjD,MAAM,OAAO,MAAMC,+BAAAA,cAA6B,UAAU,KAAK,SAAS;GACxE,OAAO;IACL;IACA,QAAQ;KACN,KAAK,KAAK;KACV,MAAM,KAAK;KACX,OAAO,KAAK;KACZ,gBAAgB;KAChB,SAAS,KAAK;KACd,YAAY,KAAK,MAAM,KAAK;KAC5B,aAAa,KAAK,MAAM,KAAK;IAC/B;GACF;EACF;EACA,MAAM,kBAAkB,EAAE,MAAM,GAAG,aAAa,GAAG,UAAmC;GACpF,CAAA,GAAA,cAAA,UAAA,CAAU,YAAY,MAAM,kBAAkB;GAC9C,MAAM,EAAE,aAAa;GACrB,MAAM,EAAE,SAAS;GACjB,MAAM,WAAW,MAAMF,+BAAAA,0BAA0B;IAAE;IAAM;IAAU,GAAG;GAAO,CAAC;GAC9E,IAAI,CAAC,SAAS,IAAI;IAChB,MAAM,EAAE,UAAW,MAAM,SAAS,KAAK;IACvC,MAAM,IAAIC,qBAAAA,YAAY,SAAS,QAAQ,KAAK;GAC9C;GACA,MAAM,QAAS,MAAM,SAAS,KAAK;GAEnC,OAAO;IAAE;IAAO,UAAA,MADO,KAAK,YAAY,KAAK;GACpB;EAC3B;CACF;AACF;AAEA,MAAa,QAAQ,oBAAoB"}
|
|
@@ -1,41 +1,42 @@
|
|
|
1
|
-
import { NativeCredential, OAuth2Token, Provider } from
|
|
2
|
-
|
|
1
|
+
import { NativeCredential, OAuth2Token, Provider } from "../types.cjs";
|
|
2
|
+
//#region src/oauth2/provider/apple.d.ts
|
|
3
3
|
declare function createAppleProvider(): Provider;
|
|
4
4
|
declare const apple: Provider;
|
|
5
5
|
interface AppleUserInfo {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
18
|
-
email: string;
|
|
6
|
+
sub: string;
|
|
7
|
+
email: string;
|
|
8
|
+
email_verified: true | 'true';
|
|
9
|
+
is_private_email: boolean;
|
|
10
|
+
real_user_status: number;
|
|
11
|
+
name: string;
|
|
12
|
+
picture: string;
|
|
13
|
+
user?: {
|
|
14
|
+
name: {
|
|
15
|
+
firstName: string;
|
|
16
|
+
lastName: string;
|
|
19
17
|
};
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
email: string;
|
|
19
|
+
};
|
|
20
|
+
nonce?: string;
|
|
21
|
+
nonce_supported?: boolean;
|
|
22
22
|
}
|
|
23
23
|
interface AppleToken extends OAuth2Token {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
access_token: string;
|
|
25
|
+
token_type: string;
|
|
26
|
+
expires_in: number;
|
|
27
|
+
refresh_token: string;
|
|
28
|
+
id_token: string;
|
|
29
29
|
}
|
|
30
30
|
interface AppleNativeCredential extends NativeCredential {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
state: string;
|
|
32
|
+
code: string;
|
|
33
|
+
id_token: string;
|
|
34
|
+
user: string;
|
|
35
|
+
email?: string;
|
|
36
36
|
}
|
|
37
37
|
interface AppleErrorResponse {
|
|
38
|
-
|
|
38
|
+
error: 'invalid_request' | 'invalid_client' | 'invalid_grant' | 'unauthorized_client' | 'unsupported_grant_type' | 'invalid_scope';
|
|
39
39
|
}
|
|
40
|
-
|
|
41
|
-
export {
|
|
40
|
+
//#endregion
|
|
41
|
+
export { AppleErrorResponse, AppleNativeCredential, AppleToken, AppleUserInfo, apple, createAppleProvider };
|
|
42
|
+
//# sourceMappingURL=apple.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apple.d.cts","names":[],"sources":["../../../src/oauth2/provider/apple.ts"],"mappings":";;iBAMgB,uBAAuB;cAwD1B,OAAK;UAGD;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;IACE;MAAQ;MAAmB;;IAC3B;;EAEF;EACA;;UAKe,mBAAmB;EAClC;EACA;EACA;EACA;EACA;;UAGe,8BAA8B;EAC7C;EACA;EACA;EAEA;EACA;;UAIe;EACf"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { NativeCredential, OAuth2Token, Provider } from "../types.mjs";
|
|
2
|
+
//#region src/oauth2/provider/apple.d.ts
|
|
3
|
+
declare function createAppleProvider(): Provider;
|
|
4
|
+
declare const apple: Provider;
|
|
5
|
+
interface AppleUserInfo {
|
|
6
|
+
sub: string;
|
|
7
|
+
email: string;
|
|
8
|
+
email_verified: true | 'true';
|
|
9
|
+
is_private_email: boolean;
|
|
10
|
+
real_user_status: number;
|
|
11
|
+
name: string;
|
|
12
|
+
picture: string;
|
|
13
|
+
user?: {
|
|
14
|
+
name: {
|
|
15
|
+
firstName: string;
|
|
16
|
+
lastName: string;
|
|
17
|
+
};
|
|
18
|
+
email: string;
|
|
19
|
+
};
|
|
20
|
+
nonce?: string;
|
|
21
|
+
nonce_supported?: boolean;
|
|
22
|
+
}
|
|
23
|
+
interface AppleToken extends OAuth2Token {
|
|
24
|
+
access_token: string;
|
|
25
|
+
token_type: string;
|
|
26
|
+
expires_in: number;
|
|
27
|
+
refresh_token: string;
|
|
28
|
+
id_token: string;
|
|
29
|
+
}
|
|
30
|
+
interface AppleNativeCredential extends NativeCredential {
|
|
31
|
+
state: string;
|
|
32
|
+
code: string;
|
|
33
|
+
id_token: string;
|
|
34
|
+
user: string;
|
|
35
|
+
email?: string;
|
|
36
|
+
}
|
|
37
|
+
interface AppleErrorResponse {
|
|
38
|
+
error: 'invalid_request' | 'invalid_client' | 'invalid_grant' | 'unauthorized_client' | 'unsupported_grant_type' | 'invalid_scope';
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
export { AppleErrorResponse, AppleNativeCredential, AppleToken, AppleUserInfo, apple, createAppleProvider };
|
|
42
|
+
//# sourceMappingURL=apple.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apple.d.mts","names":[],"sources":["../../../src/oauth2/provider/apple.ts"],"mappings":";;iBAMgB,uBAAuB;cAwD1B,OAAK;UAGD;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;IACE;MAAQ;MAAmB;;IAC3B;;EAEF;EACA;;UAKe,mBAAmB;EAClC;EACA;EACA;EACA;EACA;;UAGe,8BAA8B;EAC7C;EACA;EACA;EAEA;EACA;;UAIe;EACf"}
|
|
@@ -1,65 +1,76 @@
|
|
|
1
|
-
// src/oauth2/provider/apple.ts
|
|
2
|
-
import { invariant } from "@shware/utils";
|
|
3
1
|
import { OAuth2Error } from "../error.mjs";
|
|
4
2
|
import { createAuthorizationUri, exchangeAuthorizationCode, verifyIdToken } from "./common.mjs";
|
|
3
|
+
import { invariant } from "@shware/utils";
|
|
4
|
+
//#region src/oauth2/provider/apple.ts
|
|
5
5
|
function createAppleProvider() {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
6
|
+
return {
|
|
7
|
+
authorizationUri: "https://appleid.apple.com/auth/authorize?response_mode=form_post",
|
|
8
|
+
tokenUri: "https://appleid.apple.com/auth/token",
|
|
9
|
+
jwkSetUri: "https://appleid.apple.com/auth/keys",
|
|
10
|
+
userNameAttribute: "sub",
|
|
11
|
+
defaultScope: [
|
|
12
|
+
"openid",
|
|
13
|
+
"name",
|
|
14
|
+
"email"
|
|
15
|
+
],
|
|
16
|
+
createAuthorizationUri({ pkce: _, ...params }) {
|
|
17
|
+
return createAuthorizationUri({
|
|
18
|
+
...params,
|
|
19
|
+
scope: params.scope ?? this.defaultScope,
|
|
20
|
+
authorizationUri: this.authorizationUri
|
|
21
|
+
});
|
|
22
|
+
},
|
|
23
|
+
async exchangeAuthorizationCode({ pkce: _, ...params }) {
|
|
24
|
+
const response = await exchangeAuthorizationCode({
|
|
25
|
+
...params,
|
|
26
|
+
tokenUri: this.tokenUri
|
|
27
|
+
});
|
|
28
|
+
if (!response.ok) {
|
|
29
|
+
const { error } = await response.json();
|
|
30
|
+
throw new OAuth2Error(response.status, error);
|
|
31
|
+
}
|
|
32
|
+
return await response.json();
|
|
33
|
+
},
|
|
34
|
+
async getUserInfo({ id_token }) {
|
|
35
|
+
invariant(id_token, "id_token is required");
|
|
36
|
+
invariant(this.jwkSetUri, "jwkSetUri is required");
|
|
37
|
+
const data = await verifyIdToken(id_token, this.jwkSetUri);
|
|
38
|
+
return {
|
|
39
|
+
data,
|
|
40
|
+
claims: {
|
|
41
|
+
sub: data.sub,
|
|
42
|
+
name: data.name,
|
|
43
|
+
email: data.email,
|
|
44
|
+
email_verified: true,
|
|
45
|
+
picture: data.picture,
|
|
46
|
+
given_name: data.user?.name.firstName,
|
|
47
|
+
family_name: data.user?.name.lastName
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
async loginOAuth2Native({ pkce: _, credentials, ...params }) {
|
|
52
|
+
invariant(credentials.code, "code is required");
|
|
53
|
+
const { tokenUri } = this;
|
|
54
|
+
const { code } = credentials;
|
|
55
|
+
const response = await exchangeAuthorizationCode({
|
|
56
|
+
code,
|
|
57
|
+
tokenUri,
|
|
58
|
+
...params
|
|
59
|
+
});
|
|
60
|
+
if (!response.ok) {
|
|
61
|
+
const { error } = await response.json();
|
|
62
|
+
throw new OAuth2Error(response.status, error);
|
|
63
|
+
}
|
|
64
|
+
const token = await response.json();
|
|
65
|
+
return {
|
|
66
|
+
token,
|
|
67
|
+
userInfo: await this.getUserInfo(token)
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
};
|
|
59
71
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
};
|
|
72
|
+
const apple = createAppleProvider();
|
|
73
|
+
//#endregion
|
|
74
|
+
export { apple, createAppleProvider };
|
|
75
|
+
|
|
65
76
|
//# sourceMappingURL=apple.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/oauth2/provider/apple.ts"],"sourcesContent":["import { invariant } from '@shware/utils';\nimport { OAuth2Error } from '../error';\nimport type { LoginOAuth2NativeParams, NativeCredential, OAuth2Token, Provider } from '../types';\nimport { createAuthorizationUri, exchangeAuthorizationCode, verifyIdToken } from './common';\n\n// ref: https://account.apple.com/.well-known/openid-configuration\nexport function createAppleProvider(): Provider {\n return {\n // important notice: response_mode=form_post is required for apple\n authorizationUri: 'https://appleid.apple.com/auth/authorize?response_mode=form_post',\n tokenUri: 'https://appleid.apple.com/auth/token',\n jwkSetUri: 'https://appleid.apple.com/auth/keys',\n userNameAttribute: 'sub',\n defaultScope: ['openid', 'name', 'email'],\n createAuthorizationUri({ pkce: _, ...params }) {\n return createAuthorizationUri({\n ...params,\n scope: params.scope ?? this.defaultScope,\n authorizationUri: this.authorizationUri,\n });\n },\n async exchangeAuthorizationCode({ pkce: _, ...params }) {\n const response = await exchangeAuthorizationCode({ ...params, tokenUri: this.tokenUri });\n if (!response.ok) {\n const { error } = (await response.json()) as AppleErrorResponse;\n throw new OAuth2Error(response.status, error);\n }\n return (await response.json()) as AppleToken;\n },\n async getUserInfo({ id_token }) {\n invariant(id_token, 'id_token is required');\n invariant(this.jwkSetUri, 'jwkSetUri is required');\n const data = await verifyIdToken<AppleUserInfo>(id_token, this.jwkSetUri);\n return {\n data,\n claims: {\n sub: data.sub,\n name: data.name,\n email: data.email,\n email_verified: true,\n picture: data.picture,\n given_name: data.user?.name.firstName,\n family_name: data.user?.name.lastName,\n },\n };\n },\n async loginOAuth2Native({ pkce: _, credentials, ...params }: LoginOAuth2NativeParams) {\n invariant(credentials.code, 'code is required');\n const { tokenUri } = this;\n const { code } = credentials;\n const response = await exchangeAuthorizationCode({ code, tokenUri, ...params });\n if (!response.ok) {\n const { error } = (await response.json()) as AppleErrorResponse;\n throw new OAuth2Error(response.status, error);\n }\n const token = (await response.json()) as AppleToken;\n const userInfo = await this.getUserInfo(token);\n return { token, userInfo };\n },\n };\n}\n\nexport const apple = createAppleProvider();\n\n// https://developer.apple.com/documentation/sign_in_with_apple/authenticating-users-with-sign-in-with-apple\nexport interface AppleUserInfo {\n sub: string;\n email: string;\n email_verified: true | 'true';\n is_private_email: boolean;\n real_user_status: number;\n name: string;\n picture: string;\n user?: {\n name: { firstName: string; lastName: string };\n email: string;\n };\n nonce?: string;\n nonce_supported?: boolean;\n}\n\n// https://developer.apple.com/documentation/devicemanagement/implementing-the-oauth2-authentication-user-enrollment-flow\n// https://developer.apple.com/documentation/sign_in_with_apple/generate_and_validate_tokens\nexport interface AppleToken extends OAuth2Token {\n access_token: string;\n token_type: string;\n expires_in: number;\n refresh_token: string;\n id_token: string;\n}\n\nexport interface AppleNativeCredential extends NativeCredential {\n state: string;\n code: string;\n id_token: string;\n // no standard fields\n user: string;\n email?: string;\n}\n\n// https://developer.apple.com/documentation/sign_in_with_apple/errorresponse\nexport interface AppleErrorResponse {\n error:\n | 'invalid_request'\n | 'invalid_client'\n | 'invalid_grant'\n | 'unauthorized_client'\n | 'unsupported_grant_type'\n | 'invalid_scope';\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"apple.mjs","names":[],"sources":["../../../src/oauth2/provider/apple.ts"],"sourcesContent":["import { invariant } from '@shware/utils';\nimport { OAuth2Error } from '../error';\nimport type { LoginOAuth2NativeParams, NativeCredential, OAuth2Token, Provider } from '../types';\nimport { createAuthorizationUri, exchangeAuthorizationCode, verifyIdToken } from './common';\n\n// ref: https://account.apple.com/.well-known/openid-configuration\nexport function createAppleProvider(): Provider {\n return {\n // important notice: response_mode=form_post is required for apple\n authorizationUri: 'https://appleid.apple.com/auth/authorize?response_mode=form_post',\n tokenUri: 'https://appleid.apple.com/auth/token',\n jwkSetUri: 'https://appleid.apple.com/auth/keys',\n userNameAttribute: 'sub',\n defaultScope: ['openid', 'name', 'email'],\n createAuthorizationUri({ pkce: _, ...params }) {\n return createAuthorizationUri({\n ...params,\n scope: params.scope ?? this.defaultScope,\n authorizationUri: this.authorizationUri,\n });\n },\n async exchangeAuthorizationCode({ pkce: _, ...params }) {\n const response = await exchangeAuthorizationCode({ ...params, tokenUri: this.tokenUri });\n if (!response.ok) {\n const { error } = (await response.json()) as AppleErrorResponse;\n throw new OAuth2Error(response.status, error);\n }\n return (await response.json()) as AppleToken;\n },\n async getUserInfo({ id_token }) {\n invariant(id_token, 'id_token is required');\n invariant(this.jwkSetUri, 'jwkSetUri is required');\n const data = await verifyIdToken<AppleUserInfo>(id_token, this.jwkSetUri);\n return {\n data,\n claims: {\n sub: data.sub,\n name: data.name,\n email: data.email,\n email_verified: true,\n picture: data.picture,\n given_name: data.user?.name.firstName,\n family_name: data.user?.name.lastName,\n },\n };\n },\n async loginOAuth2Native({ pkce: _, credentials, ...params }: LoginOAuth2NativeParams) {\n invariant(credentials.code, 'code is required');\n const { tokenUri } = this;\n const { code } = credentials;\n const response = await exchangeAuthorizationCode({ code, tokenUri, ...params });\n if (!response.ok) {\n const { error } = (await response.json()) as AppleErrorResponse;\n throw new OAuth2Error(response.status, error);\n }\n const token = (await response.json()) as AppleToken;\n const userInfo = await this.getUserInfo(token);\n return { token, userInfo };\n },\n };\n}\n\nexport const apple = createAppleProvider();\n\n// https://developer.apple.com/documentation/sign_in_with_apple/authenticating-users-with-sign-in-with-apple\nexport interface AppleUserInfo {\n sub: string;\n email: string;\n email_verified: true | 'true';\n is_private_email: boolean;\n real_user_status: number;\n name: string;\n picture: string;\n user?: {\n name: { firstName: string; lastName: string };\n email: string;\n };\n nonce?: string;\n nonce_supported?: boolean;\n}\n\n// https://developer.apple.com/documentation/devicemanagement/implementing-the-oauth2-authentication-user-enrollment-flow\n// https://developer.apple.com/documentation/sign_in_with_apple/generate_and_validate_tokens\nexport interface AppleToken extends OAuth2Token {\n access_token: string;\n token_type: string;\n expires_in: number;\n refresh_token: string;\n id_token: string;\n}\n\nexport interface AppleNativeCredential extends NativeCredential {\n state: string;\n code: string;\n id_token: string;\n // no standard fields\n user: string;\n email?: string;\n}\n\n// https://developer.apple.com/documentation/sign_in_with_apple/errorresponse\nexport interface AppleErrorResponse {\n error:\n | 'invalid_request'\n | 'invalid_client'\n | 'invalid_grant'\n | 'unauthorized_client'\n | 'unsupported_grant_type'\n | 'invalid_scope';\n}\n"],"mappings":";;;;AAMA,SAAgB,sBAAgC;CAC9C,OAAO;EAEL,kBAAkB;EAClB,UAAU;EACV,WAAW;EACX,mBAAmB;EACnB,cAAc;GAAC;GAAU;GAAQ;EAAO;EACxC,uBAAuB,EAAE,MAAM,GAAG,GAAG,UAAU;GAC7C,OAAO,uBAAuB;IAC5B,GAAG;IACH,OAAO,OAAO,SAAS,KAAK;IAC5B,kBAAkB,KAAK;GACzB,CAAC;EACH;EACA,MAAM,0BAA0B,EAAE,MAAM,GAAG,GAAG,UAAU;GACtD,MAAM,WAAW,MAAM,0BAA0B;IAAE,GAAG;IAAQ,UAAU,KAAK;GAAS,CAAC;GACvF,IAAI,CAAC,SAAS,IAAI;IAChB,MAAM,EAAE,UAAW,MAAM,SAAS,KAAK;IACvC,MAAM,IAAI,YAAY,SAAS,QAAQ,KAAK;GAC9C;GACA,OAAQ,MAAM,SAAS,KAAK;EAC9B;EACA,MAAM,YAAY,EAAE,YAAY;GAC9B,UAAU,UAAU,sBAAsB;GAC1C,UAAU,KAAK,WAAW,uBAAuB;GACjD,MAAM,OAAO,MAAM,cAA6B,UAAU,KAAK,SAAS;GACxE,OAAO;IACL;IACA,QAAQ;KACN,KAAK,KAAK;KACV,MAAM,KAAK;KACX,OAAO,KAAK;KACZ,gBAAgB;KAChB,SAAS,KAAK;KACd,YAAY,KAAK,MAAM,KAAK;KAC5B,aAAa,KAAK,MAAM,KAAK;IAC/B;GACF;EACF;EACA,MAAM,kBAAkB,EAAE,MAAM,GAAG,aAAa,GAAG,UAAmC;GACpF,UAAU,YAAY,MAAM,kBAAkB;GAC9C,MAAM,EAAE,aAAa;GACrB,MAAM,EAAE,SAAS;GACjB,MAAM,WAAW,MAAM,0BAA0B;IAAE;IAAM;IAAU,GAAG;GAAO,CAAC;GAC9E,IAAI,CAAC,SAAS,IAAI;IAChB,MAAM,EAAE,UAAW,MAAM,SAAS,KAAK;IACvC,MAAM,IAAI,YAAY,SAAS,QAAQ,KAAK;GAC9C;GACA,MAAM,QAAS,MAAM,SAAS,KAAK;GAEnC,OAAO;IAAE;IAAO,UAAA,MADO,KAAK,YAAY,KAAK;GACpB;EAC3B;CACF;AACF;AAEA,MAAa,QAAQ,oBAAoB"}
|