@logto/angular 1.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/LICENSE +21 -0
- package/README.md +3 -0
- package/lib/index.d.ts +113 -0
- package/lib/index.js +64 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Silverhand
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { Prompt, type SignInUriParameters } from '@logto/js';
|
|
2
|
+
import { type OpenIdConfiguration } from 'angular-auth-oidc-client';
|
|
3
|
+
/** The Logto configuration object for Angular apps. */
|
|
4
|
+
export type LogtoAngularConfig = {
|
|
5
|
+
/**
|
|
6
|
+
* The endpoint for the Logto server, you can get it from the integration guide
|
|
7
|
+
* or the team settings page of the Logto Console.
|
|
8
|
+
*
|
|
9
|
+
* @example https://foo.logto.app
|
|
10
|
+
*/
|
|
11
|
+
endpoint: string;
|
|
12
|
+
/**
|
|
13
|
+
* The client ID of your application, you can get it from the integration guide
|
|
14
|
+
* or the application details page of the Logto Console.
|
|
15
|
+
*/
|
|
16
|
+
appId: string;
|
|
17
|
+
/**
|
|
18
|
+
* The scopes (permissions) that your application needs to access.
|
|
19
|
+
* Scopes that will be added by default: `openid`, `offline_access` and `profile`.
|
|
20
|
+
*/
|
|
21
|
+
scopes?: string[];
|
|
22
|
+
/**
|
|
23
|
+
* The API resource that your application needs to access.
|
|
24
|
+
*
|
|
25
|
+
* @see {@link https://docs.logto.io/docs/recipes/rbac/ | RBAC} to learn more about how to use
|
|
26
|
+
* role-based access control (RBAC) to protect API resources.
|
|
27
|
+
*/
|
|
28
|
+
resource?: string;
|
|
29
|
+
/**
|
|
30
|
+
* @param redirectUri The redirect URI that the user will be redirected to after the sign-in flow
|
|
31
|
+
* is completed.
|
|
32
|
+
*/
|
|
33
|
+
redirectUri: string;
|
|
34
|
+
/**
|
|
35
|
+
* @param postLogoutRedirectUri The URI that the user will be redirected to after the sign-out
|
|
36
|
+
* flow is completed.
|
|
37
|
+
*/
|
|
38
|
+
postLogoutRedirectUri?: string;
|
|
39
|
+
/**
|
|
40
|
+
* The prompt parameter to be used for the authorization request.
|
|
41
|
+
*
|
|
42
|
+
* @default Prompt.Consent
|
|
43
|
+
*/
|
|
44
|
+
prompt?: Prompt | Prompt[];
|
|
45
|
+
/**
|
|
46
|
+
* Whether to include reserved scopes (`openid`, `offline_access` and `profile`) in the scopes.
|
|
47
|
+
*
|
|
48
|
+
* @default true
|
|
49
|
+
*/
|
|
50
|
+
includeReservedScopes?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Login hint indicates the current user (usually an email address or a phone number).
|
|
53
|
+
*
|
|
54
|
+
* @link SignInUriParameters.loginHint
|
|
55
|
+
*/
|
|
56
|
+
loginHint?: SignInUriParameters['loginHint'];
|
|
57
|
+
/**
|
|
58
|
+
* The first screen to be shown in the sign-in experience.
|
|
59
|
+
*
|
|
60
|
+
* @link SignInUriParameters.firstScreen
|
|
61
|
+
*/
|
|
62
|
+
firstScreen?: SignInUriParameters['firstScreen'];
|
|
63
|
+
/**
|
|
64
|
+
* Identifiers used in the identifier sign-in, identifier register or reset password pages.
|
|
65
|
+
*
|
|
66
|
+
* Note: This parameter is applicable only when the `firstScreen` is set to either`identifierSignIn`
|
|
67
|
+
* or `identifierRegister`.
|
|
68
|
+
*
|
|
69
|
+
* @link SignInUriParameters.identifiers
|
|
70
|
+
*/
|
|
71
|
+
identifiers?: SignInUriParameters['identifiers'];
|
|
72
|
+
/**
|
|
73
|
+
* Direct sign-in options.
|
|
74
|
+
*
|
|
75
|
+
* @link SignInUriParameters.directSignIn
|
|
76
|
+
*/
|
|
77
|
+
directSignIn?: SignInUriParameters['directSignIn'];
|
|
78
|
+
/**
|
|
79
|
+
* Extra parameters to be appended to the sign-in URI.
|
|
80
|
+
*
|
|
81
|
+
* Note: The parameters should be supported by the authorization server.
|
|
82
|
+
*
|
|
83
|
+
* @link SignInUriParameters.extraParams
|
|
84
|
+
*/
|
|
85
|
+
extraParams?: SignInUriParameters['extraParams'];
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* A helper function to build the OpenID Connect configuration for `angular-auth-oidc-client`
|
|
89
|
+
* using a Logto-friendly way.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* // A minimal example
|
|
94
|
+
* import { buildAngularAuthConfig } from '@logto/js';
|
|
95
|
+
* import { provideAuth } from 'angular-auth-oidc-client';
|
|
96
|
+
*
|
|
97
|
+
* provideAuth({
|
|
98
|
+
* config: buildAngularAuthConfig({
|
|
99
|
+
* endpoint: '<your-logto-endpoint>',
|
|
100
|
+
* appId: '<your-app-id>',
|
|
101
|
+
* redirectUri: '<your-app-redirect-uri>',
|
|
102
|
+
* }),
|
|
103
|
+
* });
|
|
104
|
+
* ```
|
|
105
|
+
*
|
|
106
|
+
* @param logtoConfig The Logto configuration object for Angular apps.
|
|
107
|
+
* @returns The OpenID Connect configuration for `angular-auth-oidc-client`.
|
|
108
|
+
* @see {@link https://angular-auth-oidc-client.com/ | angular-auth-oidc-client} to learn more
|
|
109
|
+
* about how to use the library.
|
|
110
|
+
*/
|
|
111
|
+
export declare const buildAngularAuthConfig: (logtoConfig: LogtoAngularConfig) => OpenIdConfiguration;
|
|
112
|
+
export type { UserInfoResponse } from '@logto/js';
|
|
113
|
+
export { UserScope } from '@logto/js';
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Prompt, withReservedScopes, QueryKey } from '@logto/js';
|
|
2
|
+
export { UserScope } from '@logto/js';
|
|
3
|
+
import { conditional } from '@silverhand/essentials';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A helper function to build the OpenID Connect configuration for `angular-auth-oidc-client`
|
|
7
|
+
* using a Logto-friendly way.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* // A minimal example
|
|
12
|
+
* import { buildAngularAuthConfig } from '@logto/js';
|
|
13
|
+
* import { provideAuth } from 'angular-auth-oidc-client';
|
|
14
|
+
*
|
|
15
|
+
* provideAuth({
|
|
16
|
+
* config: buildAngularAuthConfig({
|
|
17
|
+
* endpoint: '<your-logto-endpoint>',
|
|
18
|
+
* appId: '<your-app-id>',
|
|
19
|
+
* redirectUri: '<your-app-redirect-uri>',
|
|
20
|
+
* }),
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @param logtoConfig The Logto configuration object for Angular apps.
|
|
25
|
+
* @returns The OpenID Connect configuration for `angular-auth-oidc-client`.
|
|
26
|
+
* @see {@link https://angular-auth-oidc-client.com/ | angular-auth-oidc-client} to learn more
|
|
27
|
+
* about how to use the library.
|
|
28
|
+
*/
|
|
29
|
+
const buildAngularAuthConfig = (logtoConfig) => {
|
|
30
|
+
const { endpoint, appId: clientId, scopes, resource, redirectUri: redirectUrl, postLogoutRedirectUri, prompt = Prompt.Consent, includeReservedScopes = true, loginHint, identifiers, firstScreen, directSignIn, extraParams, } = logtoConfig;
|
|
31
|
+
const scope = includeReservedScopes ? withReservedScopes(scopes) : scopes?.join(' ');
|
|
32
|
+
const customParameters = {
|
|
33
|
+
...conditional(resource && { [QueryKey.Resource]: resource }),
|
|
34
|
+
...conditional(loginHint && { [QueryKey.LoginHint]: loginHint }),
|
|
35
|
+
...conditional(firstScreen && { [QueryKey.FirstScreen]: firstScreen }),
|
|
36
|
+
...conditional(identifiers && { [QueryKey.Identifier]: identifiers.join(' ') }),
|
|
37
|
+
...conditional(directSignIn && { [QueryKey.DirectSignIn]: `${directSignIn.method}:${directSignIn.target}` }),
|
|
38
|
+
...extraParams,
|
|
39
|
+
};
|
|
40
|
+
return {
|
|
41
|
+
authority: new URL('/oidc', endpoint).href,
|
|
42
|
+
redirectUrl,
|
|
43
|
+
postLogoutRedirectUri,
|
|
44
|
+
clientId,
|
|
45
|
+
scope,
|
|
46
|
+
responseType: 'code',
|
|
47
|
+
autoUserInfo: !resource,
|
|
48
|
+
renewUserInfoAfterTokenRenew: !resource,
|
|
49
|
+
silentRenew: true,
|
|
50
|
+
useRefreshToken: true,
|
|
51
|
+
customParamsAuthRequest: {
|
|
52
|
+
prompt: Array.isArray(prompt) ? prompt.join(' ') : prompt,
|
|
53
|
+
...customParameters,
|
|
54
|
+
},
|
|
55
|
+
customParamsCodeRequest: {
|
|
56
|
+
...customParameters,
|
|
57
|
+
},
|
|
58
|
+
customParamsRefreshTokenRequest: {
|
|
59
|
+
...customParameters,
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export { buildAngularAuthConfig };
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@logto/angular",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"module": "./lib/index.js",
|
|
6
|
+
"types": "./lib/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
"types": "./lib/index.d.ts",
|
|
9
|
+
"import": "./lib/index.js",
|
|
10
|
+
"default": "./lib/index.js"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"lib"
|
|
14
|
+
],
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/logto-io/js.git",
|
|
19
|
+
"directory": "packages/angular"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@silverhand/essentials": "^2.9.2",
|
|
23
|
+
"@logto/js": "^6.0.0"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@silverhand/eslint-config": "^6.0.1",
|
|
27
|
+
"@silverhand/eslint-config-react": "^6.0.2",
|
|
28
|
+
"@silverhand/ts-config": "^6.0.0",
|
|
29
|
+
"@silverhand/ts-config-react": "^6.0.0",
|
|
30
|
+
"angular-auth-oidc-client": "^19.0.0",
|
|
31
|
+
"eslint": "^8.57.0",
|
|
32
|
+
"lint-staged": "^15.0.0",
|
|
33
|
+
"prettier": "^3.0.0",
|
|
34
|
+
"typescript": "^5.3.3",
|
|
35
|
+
"vitest": "^2.1.9"
|
|
36
|
+
},
|
|
37
|
+
"eslintConfig": {
|
|
38
|
+
"extends": "@silverhand"
|
|
39
|
+
},
|
|
40
|
+
"prettier": "@silverhand/eslint-config/.prettierrc",
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"dev:tsc": "tsc -p tsconfig.build.json -w --preserveWatchOutput",
|
|
46
|
+
"precommit": "lint-staged",
|
|
47
|
+
"check": "tsc --noEmit",
|
|
48
|
+
"build": "rm -rf lib/ && tsc -p tsconfig.build.json --noEmit && rollup -c",
|
|
49
|
+
"lint": "eslint --ext .ts --ext .tsx src"
|
|
50
|
+
}
|
|
51
|
+
}
|