@logto/js 1.1.0 → 1.1.2

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 (58) hide show
  1. package/lib/consts/index.d.ts +74 -0
  2. package/lib/consts/index.js +83 -0
  3. package/lib/consts/index.mjs +81 -0
  4. package/lib/core/fetch-token.d.ts +36 -0
  5. package/lib/core/fetch-token.js +47 -0
  6. package/lib/core/fetch-token.mjs +40 -0
  7. package/lib/core/fetch-token.test.d.ts +1 -0
  8. package/lib/core/index.d.ts +6 -0
  9. package/lib/core/oidc-config.d.ts +15 -0
  10. package/lib/core/oidc-config.js +13 -0
  11. package/lib/core/oidc-config.mjs +6 -0
  12. package/lib/core/oidc-config.test.d.ts +1 -0
  13. package/lib/core/revoke.d.ts +2 -0
  14. package/lib/core/revoke.js +14 -0
  15. package/lib/core/revoke.mjs +12 -0
  16. package/lib/core/revoke.test.d.ts +1 -0
  17. package/lib/core/sign-in.d.ts +14 -0
  18. package/lib/core/sign-in.js +32 -0
  19. package/lib/core/sign-in.mjs +30 -0
  20. package/lib/core/sign-in.test.d.ts +1 -0
  21. package/lib/core/sign-out.d.ts +7 -0
  22. package/lib/core/sign-out.js +13 -0
  23. package/lib/core/sign-out.mjs +11 -0
  24. package/lib/core/sign-out.test.d.ts +1 -0
  25. package/lib/core/user-info.d.ts +20 -0
  26. package/lib/core/user-info.js +7 -0
  27. package/lib/core/user-info.mjs +5 -0
  28. package/lib/core/user-info.test.d.ts +1 -0
  29. package/lib/index.d.ts +4 -224
  30. package/lib/index.js +55 -406
  31. package/lib/index.mjs +12 -0
  32. package/lib/types/index.d.ts +6 -0
  33. package/lib/utils/arbitrary-object.d.ts +1 -0
  34. package/lib/utils/arbitrary-object.js +5 -0
  35. package/lib/utils/arbitrary-object.mjs +3 -0
  36. package/lib/utils/callback-uri.d.ts +2 -0
  37. package/lib/utils/callback-uri.js +36 -0
  38. package/lib/utils/callback-uri.mjs +33 -0
  39. package/lib/utils/callback-uri.test.d.ts +1 -0
  40. package/lib/utils/errors.d.ts +36 -0
  41. package/lib/utils/errors.js +62 -0
  42. package/lib/utils/errors.mjs +53 -0
  43. package/lib/utils/errors.test.d.ts +1 -0
  44. package/lib/utils/id-token.d.ts +19 -0
  45. package/lib/utils/id-token.js +63 -0
  46. package/lib/utils/id-token.mjs +60 -0
  47. package/lib/utils/id-token.test.d.ts +1 -0
  48. package/lib/utils/index.d.ts +5 -0
  49. package/lib/utils/scopes.d.ts +5 -0
  50. package/lib/utils/scopes.js +15 -0
  51. package/lib/utils/scopes.mjs +13 -0
  52. package/lib/utils/scopes.test.d.ts +1 -0
  53. package/package.json +19 -20
  54. package/lib/index.d.ts.map +0 -1
  55. package/lib/index.js.map +0 -1
  56. package/lib/module.d.mts +0 -224
  57. package/lib/module.mjs +0 -401
  58. package/lib/module.mjs.map +0 -1
@@ -0,0 +1,74 @@
1
+ export declare const ContentType: {
2
+ formUrlEncoded: {
3
+ 'Content-Type': string;
4
+ };
5
+ };
6
+ export declare enum TokenGrantType {
7
+ AuthorizationCode = "authorization_code",
8
+ RefreshToken = "refresh_token"
9
+ }
10
+ export declare enum QueryKey {
11
+ ClientId = "client_id",
12
+ Code = "code",
13
+ CodeChallenge = "code_challenge",
14
+ CodeChallengeMethod = "code_challenge_method",
15
+ CodeVerifier = "code_verifier",
16
+ Error = "error",
17
+ ErrorDescription = "error_description",
18
+ GrantType = "grant_type",
19
+ IdToken = "id_token",
20
+ IdTokenHint = "id_token_hint",
21
+ PostLogoutRedirectUri = "post_logout_redirect_uri",
22
+ Prompt = "prompt",
23
+ RedirectUri = "redirect_uri",
24
+ RefreshToken = "refresh_token",
25
+ Resource = "resource",
26
+ ResponseType = "response_type",
27
+ Scope = "scope",
28
+ State = "state",
29
+ Token = "token",
30
+ InteractionMode = "interaction_mode"
31
+ }
32
+ export declare enum Prompt {
33
+ Consent = "consent",
34
+ Login = "login"
35
+ }
36
+ export declare enum ReservedScope {
37
+ OpenId = "openid",
38
+ OfflineAccess = "offline_access"
39
+ }
40
+ /**
41
+ * Scopes for ID Token and Userinfo Endpoint.
42
+ */
43
+ export declare enum UserScope {
44
+ /**
45
+ * Scope for basic user info.
46
+ *
47
+ * See {@link idTokenClaims} for mapped claims in ID Token and {@link userinfoClaims} for additional claims in Userinfo Endpoint.
48
+ */
49
+ Profile = "profile",
50
+ /**
51
+ * Scope for user email address.
52
+ *
53
+ * See {@link idTokenClaims} for mapped claims in ID Token and {@link userinfoClaims} for additional claims in Userinfo Endpoint.
54
+ */
55
+ Email = "email",
56
+ /**
57
+ * Scope for user phone number.
58
+ *
59
+ * See {@link idTokenClaims} for mapped claims in ID Token and {@link userinfoClaims} for additional claims in Userinfo Endpoint.
60
+ */
61
+ Phone = "phone",
62
+ /**
63
+ * Scope for user's custom data.
64
+ *
65
+ * See {@link idTokenClaims} for mapped claims in ID Token and {@link userinfoClaims} for additional claims in Userinfo Endpoint.
66
+ */
67
+ CustomData = "custom_data",
68
+ /**
69
+ * Scope for user's social identity details.
70
+ *
71
+ * See {@link idTokenClaims} for mapped claims in ID Token and {@link userinfoClaims} for additional claims in Userinfo Endpoint.
72
+ */
73
+ Identities = "identities"
74
+ }
@@ -0,0 +1,83 @@
1
+ 'use strict';
2
+
3
+ const ContentType = {
4
+ formUrlEncoded: { 'Content-Type': 'application/x-www-form-urlencoded' },
5
+ };
6
+ exports.TokenGrantType = void 0;
7
+ (function (TokenGrantType) {
8
+ TokenGrantType["AuthorizationCode"] = "authorization_code";
9
+ TokenGrantType["RefreshToken"] = "refresh_token";
10
+ })(exports.TokenGrantType || (exports.TokenGrantType = {}));
11
+ exports.QueryKey = void 0;
12
+ (function (QueryKey) {
13
+ QueryKey["ClientId"] = "client_id";
14
+ QueryKey["Code"] = "code";
15
+ QueryKey["CodeChallenge"] = "code_challenge";
16
+ QueryKey["CodeChallengeMethod"] = "code_challenge_method";
17
+ QueryKey["CodeVerifier"] = "code_verifier";
18
+ QueryKey["Error"] = "error";
19
+ QueryKey["ErrorDescription"] = "error_description";
20
+ QueryKey["GrantType"] = "grant_type";
21
+ QueryKey["IdToken"] = "id_token";
22
+ QueryKey["IdTokenHint"] = "id_token_hint";
23
+ QueryKey["PostLogoutRedirectUri"] = "post_logout_redirect_uri";
24
+ QueryKey["Prompt"] = "prompt";
25
+ QueryKey["RedirectUri"] = "redirect_uri";
26
+ QueryKey["RefreshToken"] = "refresh_token";
27
+ QueryKey["Resource"] = "resource";
28
+ QueryKey["ResponseType"] = "response_type";
29
+ QueryKey["Scope"] = "scope";
30
+ QueryKey["State"] = "state";
31
+ QueryKey["Token"] = "token";
32
+ // Need to align with the OIDC extraParams settings in core
33
+ QueryKey["InteractionMode"] = "interaction_mode";
34
+ })(exports.QueryKey || (exports.QueryKey = {}));
35
+ exports.Prompt = void 0;
36
+ (function (Prompt) {
37
+ Prompt["Consent"] = "consent";
38
+ Prompt["Login"] = "login";
39
+ })(exports.Prompt || (exports.Prompt = {}));
40
+ // TODO: @sijie @charles find a proper way to sync scopes constants with core
41
+ exports.ReservedScope = void 0;
42
+ (function (ReservedScope) {
43
+ ReservedScope["OpenId"] = "openid";
44
+ ReservedScope["OfflineAccess"] = "offline_access";
45
+ })(exports.ReservedScope || (exports.ReservedScope = {}));
46
+ /**
47
+ * Scopes for ID Token and Userinfo Endpoint.
48
+ */
49
+ exports.UserScope = void 0;
50
+ (function (UserScope) {
51
+ /**
52
+ * Scope for basic user info.
53
+ *
54
+ * See {@link idTokenClaims} for mapped claims in ID Token and {@link userinfoClaims} for additional claims in Userinfo Endpoint.
55
+ */
56
+ UserScope["Profile"] = "profile";
57
+ /**
58
+ * Scope for user email address.
59
+ *
60
+ * See {@link idTokenClaims} for mapped claims in ID Token and {@link userinfoClaims} for additional claims in Userinfo Endpoint.
61
+ */
62
+ UserScope["Email"] = "email";
63
+ /**
64
+ * Scope for user phone number.
65
+ *
66
+ * See {@link idTokenClaims} for mapped claims in ID Token and {@link userinfoClaims} for additional claims in Userinfo Endpoint.
67
+ */
68
+ UserScope["Phone"] = "phone";
69
+ /**
70
+ * Scope for user's custom data.
71
+ *
72
+ * See {@link idTokenClaims} for mapped claims in ID Token and {@link userinfoClaims} for additional claims in Userinfo Endpoint.
73
+ */
74
+ UserScope["CustomData"] = "custom_data";
75
+ /**
76
+ * Scope for user's social identity details.
77
+ *
78
+ * See {@link idTokenClaims} for mapped claims in ID Token and {@link userinfoClaims} for additional claims in Userinfo Endpoint.
79
+ */
80
+ UserScope["Identities"] = "identities";
81
+ })(exports.UserScope || (exports.UserScope = {}));
82
+
83
+ exports.ContentType = ContentType;
@@ -0,0 +1,81 @@
1
+ const ContentType = {
2
+ formUrlEncoded: { 'Content-Type': 'application/x-www-form-urlencoded' },
3
+ };
4
+ var TokenGrantType;
5
+ (function (TokenGrantType) {
6
+ TokenGrantType["AuthorizationCode"] = "authorization_code";
7
+ TokenGrantType["RefreshToken"] = "refresh_token";
8
+ })(TokenGrantType || (TokenGrantType = {}));
9
+ var QueryKey;
10
+ (function (QueryKey) {
11
+ QueryKey["ClientId"] = "client_id";
12
+ QueryKey["Code"] = "code";
13
+ QueryKey["CodeChallenge"] = "code_challenge";
14
+ QueryKey["CodeChallengeMethod"] = "code_challenge_method";
15
+ QueryKey["CodeVerifier"] = "code_verifier";
16
+ QueryKey["Error"] = "error";
17
+ QueryKey["ErrorDescription"] = "error_description";
18
+ QueryKey["GrantType"] = "grant_type";
19
+ QueryKey["IdToken"] = "id_token";
20
+ QueryKey["IdTokenHint"] = "id_token_hint";
21
+ QueryKey["PostLogoutRedirectUri"] = "post_logout_redirect_uri";
22
+ QueryKey["Prompt"] = "prompt";
23
+ QueryKey["RedirectUri"] = "redirect_uri";
24
+ QueryKey["RefreshToken"] = "refresh_token";
25
+ QueryKey["Resource"] = "resource";
26
+ QueryKey["ResponseType"] = "response_type";
27
+ QueryKey["Scope"] = "scope";
28
+ QueryKey["State"] = "state";
29
+ QueryKey["Token"] = "token";
30
+ // Need to align with the OIDC extraParams settings in core
31
+ QueryKey["InteractionMode"] = "interaction_mode";
32
+ })(QueryKey || (QueryKey = {}));
33
+ var Prompt;
34
+ (function (Prompt) {
35
+ Prompt["Consent"] = "consent";
36
+ Prompt["Login"] = "login";
37
+ })(Prompt || (Prompt = {}));
38
+ // TODO: @sijie @charles find a proper way to sync scopes constants with core
39
+ var ReservedScope;
40
+ (function (ReservedScope) {
41
+ ReservedScope["OpenId"] = "openid";
42
+ ReservedScope["OfflineAccess"] = "offline_access";
43
+ })(ReservedScope || (ReservedScope = {}));
44
+ /**
45
+ * Scopes for ID Token and Userinfo Endpoint.
46
+ */
47
+ var UserScope;
48
+ (function (UserScope) {
49
+ /**
50
+ * Scope for basic user info.
51
+ *
52
+ * See {@link idTokenClaims} for mapped claims in ID Token and {@link userinfoClaims} for additional claims in Userinfo Endpoint.
53
+ */
54
+ UserScope["Profile"] = "profile";
55
+ /**
56
+ * Scope for user email address.
57
+ *
58
+ * See {@link idTokenClaims} for mapped claims in ID Token and {@link userinfoClaims} for additional claims in Userinfo Endpoint.
59
+ */
60
+ UserScope["Email"] = "email";
61
+ /**
62
+ * Scope for user phone number.
63
+ *
64
+ * See {@link idTokenClaims} for mapped claims in ID Token and {@link userinfoClaims} for additional claims in Userinfo Endpoint.
65
+ */
66
+ UserScope["Phone"] = "phone";
67
+ /**
68
+ * Scope for user's custom data.
69
+ *
70
+ * See {@link idTokenClaims} for mapped claims in ID Token and {@link userinfoClaims} for additional claims in Userinfo Endpoint.
71
+ */
72
+ UserScope["CustomData"] = "custom_data";
73
+ /**
74
+ * Scope for user's social identity details.
75
+ *
76
+ * See {@link idTokenClaims} for mapped claims in ID Token and {@link userinfoClaims} for additional claims in Userinfo Endpoint.
77
+ */
78
+ UserScope["Identities"] = "identities";
79
+ })(UserScope || (UserScope = {}));
80
+
81
+ export { ContentType, Prompt, QueryKey, ReservedScope, TokenGrantType, UserScope };
@@ -0,0 +1,36 @@
1
+ import type { KeysToCamelCase } from '@silverhand/essentials';
2
+ import type { Requester } from '../types';
3
+ export type FetchTokenByAuthorizationCodeParameters = {
4
+ clientId: string;
5
+ tokenEndpoint: string;
6
+ redirectUri: string;
7
+ codeVerifier: string;
8
+ code: string;
9
+ resource?: string;
10
+ };
11
+ export type FetchTokenByRefreshTokenParameters = {
12
+ clientId: string;
13
+ tokenEndpoint: string;
14
+ refreshToken: string;
15
+ resource?: string;
16
+ scopes?: string[];
17
+ };
18
+ type SnakeCaseCodeTokenResponse = {
19
+ access_token: string;
20
+ refresh_token?: string;
21
+ id_token: string;
22
+ scope: string;
23
+ expires_in: number;
24
+ };
25
+ export type CodeTokenResponse = KeysToCamelCase<SnakeCaseCodeTokenResponse>;
26
+ type SnakeCaseRefreshTokenTokenResponse = {
27
+ access_token: string;
28
+ refresh_token: string;
29
+ id_token?: string;
30
+ scope: string;
31
+ expires_in: number;
32
+ };
33
+ export type RefreshTokenTokenResponse = KeysToCamelCase<SnakeCaseRefreshTokenTokenResponse>;
34
+ export declare const fetchTokenByAuthorizationCode: ({ clientId, tokenEndpoint, redirectUri, codeVerifier, code, resource, }: FetchTokenByAuthorizationCodeParameters, requester: Requester) => Promise<CodeTokenResponse>;
35
+ export declare const fetchTokenByRefreshToken: ({ clientId, tokenEndpoint, refreshToken, resource, scopes }: FetchTokenByRefreshTokenParameters, requester: Requester) => Promise<RefreshTokenTokenResponse>;
36
+ export {};
@@ -0,0 +1,47 @@
1
+ 'use strict';
2
+
3
+ var camelcaseKeys = require('camelcase-keys');
4
+ var index = require('../consts/index.js');
5
+
6
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
+
8
+ var camelcaseKeys__default = /*#__PURE__*/_interopDefault(camelcaseKeys);
9
+
10
+ const fetchTokenByAuthorizationCode = async ({ clientId, tokenEndpoint, redirectUri, codeVerifier, code, resource, }, requester) => {
11
+ const parameters = new URLSearchParams();
12
+ parameters.append(index.QueryKey.ClientId, clientId);
13
+ parameters.append(index.QueryKey.Code, code);
14
+ parameters.append(index.QueryKey.CodeVerifier, codeVerifier);
15
+ parameters.append(index.QueryKey.RedirectUri, redirectUri);
16
+ parameters.append(index.QueryKey.GrantType, index.TokenGrantType.AuthorizationCode);
17
+ if (resource) {
18
+ parameters.append(index.QueryKey.Resource, resource);
19
+ }
20
+ const snakeCaseCodeTokenResponse = await requester(tokenEndpoint, {
21
+ method: 'POST',
22
+ headers: index.ContentType.formUrlEncoded,
23
+ body: parameters,
24
+ });
25
+ return camelcaseKeys__default.default(snakeCaseCodeTokenResponse);
26
+ };
27
+ const fetchTokenByRefreshToken = async ({ clientId, tokenEndpoint, refreshToken, resource, scopes }, requester) => {
28
+ const parameters = new URLSearchParams();
29
+ parameters.append(index.QueryKey.ClientId, clientId);
30
+ parameters.append(index.QueryKey.RefreshToken, refreshToken);
31
+ parameters.append(index.QueryKey.GrantType, index.TokenGrantType.RefreshToken);
32
+ if (resource) {
33
+ parameters.append(index.QueryKey.Resource, resource);
34
+ }
35
+ if (scopes?.length) {
36
+ parameters.append(index.QueryKey.Scope, scopes.join(' '));
37
+ }
38
+ const snakeCaseRefreshTokenTokenResponse = await requester(tokenEndpoint, {
39
+ method: 'POST',
40
+ headers: index.ContentType.formUrlEncoded,
41
+ body: parameters,
42
+ });
43
+ return camelcaseKeys__default.default(snakeCaseRefreshTokenTokenResponse);
44
+ };
45
+
46
+ exports.fetchTokenByAuthorizationCode = fetchTokenByAuthorizationCode;
47
+ exports.fetchTokenByRefreshToken = fetchTokenByRefreshToken;
@@ -0,0 +1,40 @@
1
+ import camelcaseKeys from 'camelcase-keys';
2
+ import { QueryKey, TokenGrantType, ContentType } from '../consts/index.mjs';
3
+
4
+ const fetchTokenByAuthorizationCode = async ({ clientId, tokenEndpoint, redirectUri, codeVerifier, code, resource, }, requester) => {
5
+ const parameters = new URLSearchParams();
6
+ parameters.append(QueryKey.ClientId, clientId);
7
+ parameters.append(QueryKey.Code, code);
8
+ parameters.append(QueryKey.CodeVerifier, codeVerifier);
9
+ parameters.append(QueryKey.RedirectUri, redirectUri);
10
+ parameters.append(QueryKey.GrantType, TokenGrantType.AuthorizationCode);
11
+ if (resource) {
12
+ parameters.append(QueryKey.Resource, resource);
13
+ }
14
+ const snakeCaseCodeTokenResponse = await requester(tokenEndpoint, {
15
+ method: 'POST',
16
+ headers: ContentType.formUrlEncoded,
17
+ body: parameters,
18
+ });
19
+ return camelcaseKeys(snakeCaseCodeTokenResponse);
20
+ };
21
+ const fetchTokenByRefreshToken = async ({ clientId, tokenEndpoint, refreshToken, resource, scopes }, requester) => {
22
+ const parameters = new URLSearchParams();
23
+ parameters.append(QueryKey.ClientId, clientId);
24
+ parameters.append(QueryKey.RefreshToken, refreshToken);
25
+ parameters.append(QueryKey.GrantType, TokenGrantType.RefreshToken);
26
+ if (resource) {
27
+ parameters.append(QueryKey.Resource, resource);
28
+ }
29
+ if (scopes?.length) {
30
+ parameters.append(QueryKey.Scope, scopes.join(' '));
31
+ }
32
+ const snakeCaseRefreshTokenTokenResponse = await requester(tokenEndpoint, {
33
+ method: 'POST',
34
+ headers: ContentType.formUrlEncoded,
35
+ body: parameters,
36
+ });
37
+ return camelcaseKeys(snakeCaseRefreshTokenTokenResponse);
38
+ };
39
+
40
+ export { fetchTokenByAuthorizationCode, fetchTokenByRefreshToken };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ export * from './fetch-token';
2
+ export * from './oidc-config';
3
+ export * from './revoke';
4
+ export * from './sign-in';
5
+ export * from './sign-out';
6
+ export * from './user-info';
@@ -0,0 +1,15 @@
1
+ import type { KeysToCamelCase } from '@silverhand/essentials';
2
+ import type { Requester } from '../types';
3
+ type OidcConfigSnakeCaseResponse = {
4
+ authorization_endpoint: string;
5
+ token_endpoint: string;
6
+ userinfo_endpoint: string;
7
+ end_session_endpoint: string;
8
+ revocation_endpoint: string;
9
+ jwks_uri: string;
10
+ issuer: string;
11
+ };
12
+ export declare const discoveryPath = "/oidc/.well-known/openid-configuration";
13
+ export type OidcConfigResponse = KeysToCamelCase<OidcConfigSnakeCaseResponse>;
14
+ export declare const fetchOidcConfig: (endpoint: string, requester: Requester) => Promise<OidcConfigResponse>;
15
+ export {};
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ var camelcaseKeys = require('camelcase-keys');
4
+
5
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
6
+
7
+ var camelcaseKeys__default = /*#__PURE__*/_interopDefault(camelcaseKeys);
8
+
9
+ const discoveryPath = '/oidc/.well-known/openid-configuration';
10
+ const fetchOidcConfig = async (endpoint, requester) => camelcaseKeys__default.default(await requester(endpoint));
11
+
12
+ exports.discoveryPath = discoveryPath;
13
+ exports.fetchOidcConfig = fetchOidcConfig;
@@ -0,0 +1,6 @@
1
+ import camelcaseKeys from 'camelcase-keys';
2
+
3
+ const discoveryPath = '/oidc/.well-known/openid-configuration';
4
+ const fetchOidcConfig = async (endpoint, requester) => camelcaseKeys(await requester(endpoint));
5
+
6
+ export { discoveryPath, fetchOidcConfig };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { Requester } from '../types';
2
+ export declare const revoke: (revocationEndpoint: string, clientId: string, token: string, requester: Requester) => Promise<void>;
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ var index = require('../consts/index.js');
4
+
5
+ const revoke = async (revocationEndpoint, clientId, token, requester) => requester(revocationEndpoint, {
6
+ method: 'POST',
7
+ headers: index.ContentType.formUrlEncoded,
8
+ body: new URLSearchParams({
9
+ [index.QueryKey.ClientId]: clientId,
10
+ [index.QueryKey.Token]: token,
11
+ }),
12
+ });
13
+
14
+ exports.revoke = revoke;
@@ -0,0 +1,12 @@
1
+ import { ContentType, QueryKey } from '../consts/index.mjs';
2
+
3
+ const revoke = async (revocationEndpoint, clientId, token, requester) => requester(revocationEndpoint, {
4
+ method: 'POST',
5
+ headers: ContentType.formUrlEncoded,
6
+ body: new URLSearchParams({
7
+ [QueryKey.ClientId]: clientId,
8
+ [QueryKey.Token]: token,
9
+ }),
10
+ });
11
+
12
+ export { revoke };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ import { Prompt } from '../consts';
2
+ import type { InteractionMode } from '../types';
3
+ export type SignInUriParameters = {
4
+ authorizationEndpoint: string;
5
+ clientId: string;
6
+ redirectUri: string;
7
+ codeChallenge: string;
8
+ state: string;
9
+ scopes?: string[];
10
+ resources?: string[];
11
+ prompt?: Prompt;
12
+ interactionMode?: InteractionMode;
13
+ };
14
+ export declare const generateSignInUri: ({ authorizationEndpoint, clientId, redirectUri, codeChallenge, state, scopes, resources, prompt, interactionMode, }: SignInUriParameters) => string;
@@ -0,0 +1,32 @@
1
+ 'use strict';
2
+
3
+ var index = require('../consts/index.js');
4
+ require('@silverhand/essentials');
5
+ require('lodash.get');
6
+ require('jose');
7
+ var scopes = require('../utils/scopes.js');
8
+
9
+ const codeChallengeMethod = 'S256';
10
+ const responseType = 'code';
11
+ const generateSignInUri = ({ authorizationEndpoint, clientId, redirectUri, codeChallenge, state, scopes: scopes$1, resources, prompt, interactionMode, }) => {
12
+ const urlSearchParameters = new URLSearchParams({
13
+ [index.QueryKey.ClientId]: clientId,
14
+ [index.QueryKey.RedirectUri]: redirectUri,
15
+ [index.QueryKey.CodeChallenge]: codeChallenge,
16
+ [index.QueryKey.CodeChallengeMethod]: codeChallengeMethod,
17
+ [index.QueryKey.State]: state,
18
+ [index.QueryKey.ResponseType]: responseType,
19
+ [index.QueryKey.Prompt]: prompt ?? index.Prompt.Consent,
20
+ [index.QueryKey.Scope]: scopes.withDefaultScopes(scopes$1),
21
+ });
22
+ for (const resource of resources ?? []) {
23
+ urlSearchParameters.append(index.QueryKey.Resource, resource);
24
+ }
25
+ // Set interactionMode to signUp for a create account user experience
26
+ if (interactionMode) {
27
+ urlSearchParameters.append(index.QueryKey.InteractionMode, interactionMode);
28
+ }
29
+ return `${authorizationEndpoint}?${urlSearchParameters.toString()}`;
30
+ };
31
+
32
+ exports.generateSignInUri = generateSignInUri;
@@ -0,0 +1,30 @@
1
+ import { QueryKey, Prompt } from '../consts/index.mjs';
2
+ import '@silverhand/essentials';
3
+ import 'lodash.get';
4
+ import 'jose';
5
+ import { withDefaultScopes } from '../utils/scopes.mjs';
6
+
7
+ const codeChallengeMethod = 'S256';
8
+ const responseType = 'code';
9
+ const generateSignInUri = ({ authorizationEndpoint, clientId, redirectUri, codeChallenge, state, scopes, resources, prompt, interactionMode, }) => {
10
+ const urlSearchParameters = new URLSearchParams({
11
+ [QueryKey.ClientId]: clientId,
12
+ [QueryKey.RedirectUri]: redirectUri,
13
+ [QueryKey.CodeChallenge]: codeChallenge,
14
+ [QueryKey.CodeChallengeMethod]: codeChallengeMethod,
15
+ [QueryKey.State]: state,
16
+ [QueryKey.ResponseType]: responseType,
17
+ [QueryKey.Prompt]: prompt ?? Prompt.Consent,
18
+ [QueryKey.Scope]: withDefaultScopes(scopes),
19
+ });
20
+ for (const resource of resources ?? []) {
21
+ urlSearchParameters.append(QueryKey.Resource, resource);
22
+ }
23
+ // Set interactionMode to signUp for a create account user experience
24
+ if (interactionMode) {
25
+ urlSearchParameters.append(QueryKey.InteractionMode, interactionMode);
26
+ }
27
+ return `${authorizationEndpoint}?${urlSearchParameters.toString()}`;
28
+ };
29
+
30
+ export { generateSignInUri };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ type SignOutUriParameters = {
2
+ endSessionEndpoint: string;
3
+ clientId: string;
4
+ postLogoutRedirectUri?: string;
5
+ };
6
+ export declare const generateSignOutUri: ({ endSessionEndpoint, clientId, postLogoutRedirectUri, }: SignOutUriParameters) => string;
7
+ export {};
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ var index = require('../consts/index.js');
4
+
5
+ const generateSignOutUri = ({ endSessionEndpoint, clientId, postLogoutRedirectUri, }) => {
6
+ const urlSearchParameters = new URLSearchParams({ [index.QueryKey.ClientId]: clientId });
7
+ if (postLogoutRedirectUri) {
8
+ urlSearchParameters.append(index.QueryKey.PostLogoutRedirectUri, postLogoutRedirectUri);
9
+ }
10
+ return `${endSessionEndpoint}?${urlSearchParameters.toString()}`;
11
+ };
12
+
13
+ exports.generateSignOutUri = generateSignOutUri;
@@ -0,0 +1,11 @@
1
+ import { QueryKey } from '../consts/index.mjs';
2
+
3
+ const generateSignOutUri = ({ endSessionEndpoint, clientId, postLogoutRedirectUri, }) => {
4
+ const urlSearchParameters = new URLSearchParams({ [QueryKey.ClientId]: clientId });
5
+ if (postLogoutRedirectUri) {
6
+ urlSearchParameters.append(QueryKey.PostLogoutRedirectUri, postLogoutRedirectUri);
7
+ }
8
+ return `${endSessionEndpoint}?${urlSearchParameters.toString()}`;
9
+ };
10
+
11
+ export { generateSignOutUri };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,20 @@
1
+ import type { Nullable } from '@silverhand/essentials';
2
+ import type { Requester } from '../types';
3
+ type Identity = {
4
+ userId: string;
5
+ details?: Record<string, unknown>;
6
+ };
7
+ export type UserInfoResponse = {
8
+ sub: string;
9
+ name?: Nullable<string>;
10
+ username?: Nullable<string>;
11
+ picture?: Nullable<string>;
12
+ email?: Nullable<string>;
13
+ email_verified?: boolean;
14
+ phone_number?: Nullable<string>;
15
+ phone_number_verified?: boolean;
16
+ custom_data?: unknown;
17
+ identities?: Record<string, Identity>;
18
+ };
19
+ export declare const fetchUserInfo: (userInfoEndpoint: string, accessToken: string, requester: Requester) => Promise<UserInfoResponse>;
20
+ export {};
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ const fetchUserInfo = async (userInfoEndpoint, accessToken, requester) => requester(userInfoEndpoint, {
4
+ headers: { Authorization: `Bearer ${accessToken}` },
5
+ });
6
+
7
+ exports.fetchUserInfo = fetchUserInfo;
@@ -0,0 +1,5 @@
1
+ const fetchUserInfo = async (userInfoEndpoint, accessToken, requester) => requester(userInfoEndpoint, {
2
+ headers: { Authorization: `Bearer ${accessToken}` },
3
+ });
4
+
5
+ export { fetchUserInfo };
@@ -0,0 +1 @@
1
+ export {};