|
1 | | -import { Prompt, QueryKey, type SignInUriParameters, withReservedScopes } from '@logto/js'; |
2 | | -import { conditional } from '@silverhand/essentials'; |
3 | | -import { type OpenIdConfiguration } from 'angular-auth-oidc-client'; |
| 1 | +export type { |
| 2 | + AccessTokenClaims, |
| 3 | + ClientAdapter, |
| 4 | + IdTokenClaims, |
| 5 | + InteractionMode, |
| 6 | + LogtoClientErrorCode, |
| 7 | + LogtoConfig, |
| 8 | + LogtoErrorCode, |
| 9 | + SignInOptions, |
| 10 | + Storage, |
| 11 | + UserInfoResponse, |
| 12 | +} from '@logto/browser'; |
4 | 13 |
|
5 | | -/** The Logto configuration object for Angular apps. */ |
6 | | -export type LogtoAngularConfig = { |
7 | | - /** |
8 | | - * The endpoint for the Logto server, you can get it from the integration guide |
9 | | - * or the team settings page of the Logto Console. |
10 | | - * |
11 | | - * @example https://foo.logto.app |
12 | | - */ |
13 | | - endpoint: string; |
14 | | - /** |
15 | | - * The client ID of your application, you can get it from the integration guide |
16 | | - * or the application details page of the Logto Console. |
17 | | - */ |
18 | | - appId: string; |
19 | | - /** |
20 | | - * The scopes (permissions) that your application needs to access. |
21 | | - * Scopes that will be added by default: `openid`, `offline_access` and `profile`. |
22 | | - */ |
23 | | - scopes?: string[]; |
24 | | - /** |
25 | | - * The API resource that your application needs to access. |
26 | | - * |
27 | | - * @see {@link https://docs.logto.io/docs/recipes/rbac/ | RBAC} to learn more about how to use |
28 | | - * role-based access control (RBAC) to protect API resources. |
29 | | - */ |
30 | | - resource?: string; |
31 | | - /** |
32 | | - * @param redirectUri The redirect URI that the user will be redirected to after the sign-in flow |
33 | | - * is completed. |
34 | | - */ |
35 | | - redirectUri: string; |
36 | | - /** |
37 | | - * @param postLogoutRedirectUri The URI that the user will be redirected to after the sign-out |
38 | | - * flow is completed. |
39 | | - */ |
40 | | - postLogoutRedirectUri?: string; |
41 | | - /** |
42 | | - * The prompt parameter to be used for the authorization request. |
43 | | - * |
44 | | - * @default Prompt.Consent |
45 | | - */ |
46 | | - prompt?: Prompt | Prompt[]; |
47 | | - /** |
48 | | - * Whether to include reserved scopes (`openid`, `offline_access` and `profile`) in the scopes. |
49 | | - * |
50 | | - * @default true |
51 | | - */ |
52 | | - includeReservedScopes?: boolean; |
53 | | - /** |
54 | | - * Login hint indicates the current user (usually an email address or a phone number). |
55 | | - * |
56 | | - * @link SignInUriParameters.loginHint |
57 | | - */ |
58 | | - loginHint?: SignInUriParameters['loginHint']; |
59 | | - /** |
60 | | - * The first screen to be shown in the sign-in experience. |
61 | | - * |
62 | | - * @link SignInUriParameters.firstScreen |
63 | | - */ |
64 | | - firstScreen?: SignInUriParameters['firstScreen']; |
65 | | - /** |
66 | | - * Identifiers used in the identifier sign-in, identifier register or reset password pages. |
67 | | - * |
68 | | - * Note: This parameter is applicable only when the `firstScreen` is set to either`identifierSignIn` |
69 | | - * or `identifierRegister`. |
70 | | - * |
71 | | - * @link SignInUriParameters.identifiers |
72 | | - */ |
73 | | - identifiers?: SignInUriParameters['identifiers']; |
74 | | - /** |
75 | | - * Direct sign-in options. |
76 | | - * |
77 | | - * @link SignInUriParameters.directSignIn |
78 | | - */ |
79 | | - directSignIn?: SignInUriParameters['directSignIn']; |
80 | | - /** |
81 | | - * Extra parameters to be appended to the sign-in URI. |
82 | | - * |
83 | | - * Note: The parameters should be supported by the authorization server. |
84 | | - * |
85 | | - * @link SignInUriParameters.extraParams |
86 | | - */ |
87 | | - extraParams?: SignInUriParameters['extraParams']; |
88 | | -}; |
| 14 | +export { |
| 15 | + BrowserStorage, |
| 16 | + LogtoClientError, |
| 17 | + LogtoError, |
| 18 | + LogtoRequestError, |
| 19 | + OidcError, |
| 20 | + PersistKey, |
| 21 | + Prompt, |
| 22 | + ReservedResource, |
| 23 | + ReservedScope, |
| 24 | + UserScope, |
| 25 | + buildOrganizationUrn, |
| 26 | + getOrganizationIdFromUrn, |
| 27 | + isLogtoRequestError, |
| 28 | + organizationUrnPrefix, |
| 29 | +} from '@logto/browser'; |
89 | 30 |
|
90 | | -/** |
91 | | - * A helper function to build the OpenID Connect configuration for `angular-auth-oidc-client` |
92 | | - * using a Logto-friendly way. |
93 | | - * |
94 | | - * @example |
95 | | - * ```ts |
96 | | - * // A minimal example |
97 | | - * import { buildAngularAuthConfig } from '@logto/js'; |
98 | | - * import { provideAuth } from 'angular-auth-oidc-client'; |
99 | | - * |
100 | | - * provideAuth({ |
101 | | - * config: buildAngularAuthConfig({ |
102 | | - * endpoint: '<your-logto-endpoint>', |
103 | | - * appId: '<your-app-id>', |
104 | | - * redirectUri: '<your-app-redirect-uri>', |
105 | | - * }), |
106 | | - * }); |
107 | | - * ``` |
108 | | - * |
109 | | - * @param logtoConfig The Logto configuration object for Angular apps. |
110 | | - * @returns The OpenID Connect configuration for `angular-auth-oidc-client`. |
111 | | - * @see {@link https://angular-auth-oidc-client.com/ | angular-auth-oidc-client} to learn more |
112 | | - * about how to use the library. |
113 | | - */ |
114 | | -export const buildAngularAuthConfig = (logtoConfig: LogtoAngularConfig): OpenIdConfiguration => { |
115 | | - const { |
116 | | - endpoint, |
117 | | - appId: clientId, |
118 | | - scopes, |
119 | | - resource, |
120 | | - redirectUri: redirectUrl, |
121 | | - postLogoutRedirectUri, |
122 | | - prompt = Prompt.Consent, |
123 | | - includeReservedScopes = true, |
124 | | - loginHint, |
125 | | - identifiers, |
126 | | - firstScreen, |
127 | | - directSignIn, |
128 | | - extraParams, |
129 | | - } = logtoConfig; |
130 | | - const scope = includeReservedScopes ? withReservedScopes(scopes) : scopes?.join(' '); |
131 | | - const customParameters = { |
132 | | - ...conditional(resource && { [QueryKey.Resource]: resource }), |
133 | | - ...conditional(loginHint && { [QueryKey.LoginHint]: loginHint }), |
134 | | - ...conditional(firstScreen && { [QueryKey.FirstScreen]: firstScreen }), |
135 | | - ...conditional(identifiers && { [QueryKey.Identifier]: identifiers.join(' ') }), |
136 | | - ...conditional( |
137 | | - directSignIn && { [QueryKey.DirectSignIn]: `${directSignIn.method}:${directSignIn.target}` } |
138 | | - ), |
139 | | - ...extraParams, |
140 | | - }; |
141 | | - |
142 | | - return { |
143 | | - authority: new URL('/oidc', endpoint).href, |
144 | | - redirectUrl, |
145 | | - postLogoutRedirectUri, |
146 | | - clientId, |
147 | | - scope, |
148 | | - responseType: 'code', |
149 | | - autoUserInfo: !resource, |
150 | | - renewUserInfoAfterTokenRenew: !resource, |
151 | | - silentRenew: true, |
152 | | - useRefreshToken: true, |
153 | | - customParamsAuthRequest: { |
154 | | - prompt: Array.isArray(prompt) ? prompt.join(' ') : prompt, |
155 | | - ...customParameters, |
156 | | - }, |
157 | | - customParamsCodeRequest: { |
158 | | - ...customParameters, |
159 | | - }, |
160 | | - customParamsRefreshTokenRequest: { |
161 | | - ...customParameters, |
162 | | - }, |
163 | | - }; |
164 | | -}; |
165 | | - |
166 | | -export type { UserInfoResponse } from '@logto/js'; |
167 | | -export { UserScope } from '@logto/js'; |
| 31 | +export { LOGTO_CLIENT, provideLogto, type LogtoAngularOptions } from './provider.js'; |
| 32 | +export { LogtoService } from './service.js'; |
0 commit comments