@pofsis-nbt/pofsis-auth 1.2.0 → 2.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/Documentation.md +143 -143
- package/README.md +130 -130
- package/dist/PofsisAuth.d.ts +1 -1
- package/dist/PofsisAuth.d.ts.map +1 -1
- package/dist/PofsisAuthClient-B3YHqgZL.cjs +2 -0
- package/dist/PofsisAuthClient-B3YHqgZL.cjs.map +1 -0
- package/dist/{PofsisAuthClient-c9BY8iNp.js → PofsisAuthClient-CEw_lL5S.js} +31 -80
- package/dist/PofsisAuthClient-CEw_lL5S.js.map +1 -0
- package/dist/{PofsisAuthModal-DIzzLJSP.cjs → RequireAuth-CPhXupYh.cjs} +2 -2
- package/dist/RequireAuth-CPhXupYh.cjs.map +1 -0
- package/dist/{PofsisAuthModal-DGbtRZ4f.js → RequireAuth-DFa8_MR1.js} +6 -98
- package/dist/RequireAuth-DFa8_MR1.js.map +1 -0
- package/dist/auth/authLaunch.d.ts +1 -2
- package/dist/auth/authLaunch.d.ts.map +1 -1
- package/dist/auth/config.d.ts.map +1 -1
- package/dist/components/index.d.ts +0 -1
- package/dist/components/index.d.ts.map +1 -1
- package/dist/core/PofsisAuthClient.d.ts +0 -4
- package/dist/core/PofsisAuthClient.d.ts.map +1 -1
- package/dist/core/popupProtocol.d.ts.map +1 -1
- package/dist/core.cjs +1 -1
- package/dist/core.js +1 -1
- package/dist/elements.cjs +1 -1
- package/dist/elements.cjs.map +1 -1
- package/dist/elements.js +3 -3
- package/dist/elements.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/pofsis-auth-elements.js +1 -1
- package/dist/pofsis-auth-elements.js.map +1 -1
- package/dist/react/index.d.ts +2 -2
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react.cjs +1 -1
- package/dist/react.js +2 -2
- package/dist/types.d.ts +7 -21
- package/dist/types.d.ts.map +1 -1
- package/docs/popup-integration.md +162 -178
- package/package.json +87 -87
- package/dist/PofsisAuthClient-CRYYsJYc.cjs +0 -2
- package/dist/PofsisAuthClient-CRYYsJYc.cjs.map +0 -1
- package/dist/PofsisAuthClient-c9BY8iNp.js.map +0 -1
- package/dist/PofsisAuthModal-DGbtRZ4f.js.map +0 -1
- package/dist/PofsisAuthModal-DIzzLJSP.cjs.map +0 -1
- package/dist/components/PofsisAuthModal.d.ts +0 -3
- package/dist/components/PofsisAuthModal.d.ts.map +0 -1
package/Documentation.md
CHANGED
|
@@ -1,143 +1,143 @@
|
|
|
1
|
-
# POFSIS Auth Documentation
|
|
2
|
-
|
|
3
|
-
This is the complete public API and integration reference for `@pofsis-nbt/pofsis-auth@
|
|
4
|
-
|
|
5
|
-
The repository also includes an interactive [POFSIS Auth documentation portal](./index.html) with required environment configuration, generated setup examples, and authentication scenario links. The portal does not persist or transmit entered values and is intentionally excluded from the npm package.
|
|
6
|
-
|
|
7
|
-
The [popup integration guide](./docs/popup-integration.md) is the canonical consumer reference for framework-neutral, React, and Web Component popup launches.
|
|
8
|
-
|
|
9
|
-
## Integration process
|
|
10
|
-
|
|
11
|
-
1. Install `@pofsis-nbt/pofsis-auth` with its React, React DOM, and optional Axios peers.
|
|
12
|
-
2. Import `@pofsis-nbt/pofsis-auth/style.css` once.
|
|
13
|
-
3. Wrap the application in `PofsisAuth` and supply runtime configuration.
|
|
14
|
-
4. Protect authenticated content with `RequireAuth` or use `useAuth` directly.
|
|
15
|
-
5. Register `/auth/callback` and the application origin with the POFSIS Auth service.
|
|
16
|
-
|
|
17
|
-
The consuming application owns environment lookup. The library never reads `import.meta.env`.
|
|
18
|
-
|
|
19
|
-
## Public components
|
|
20
|
-
|
|
21
|
-
### `PofsisAuth`
|
|
22
|
-
|
|
23
|
-
The provider restores the cookie-backed session, manages the in-memory access token, coordinates cross-tab logout, runs OAuth/PKCE, and handles fixed auth paths.
|
|
24
|
-
|
|
25
|
-
`PofsisAuthProps`:
|
|
26
|
-
|
|
27
|
-
| Prop | Type | Required | Meaning |
|
|
28
|
-
| --------------- | ------------------------ | -------- | -------------------------------------- |
|
|
29
|
-
| `children` | `ReactNode` | yes | Application content |
|
|
30
|
-
| `
|
|
31
|
-
| `apiBaseUrl` | `string` | yes | Auth API base URL |
|
|
32
|
-
| `authUrl` | `string` | yes | OAuth authorize URL |
|
|
33
|
-
| `scope` | `string` | no | Defaults to `openid profile email` |
|
|
34
|
-
| `postLoginPath` | `string` | no | Callback destination; defaults to `/` |
|
|
35
|
-
| `components` | `AuthComponentOverrides` | no | Custom loading and error screens |
|
|
36
|
-
|
|
37
|
-
```tsx
|
|
38
|
-
<PofsisAuth
|
|
39
|
-
|
|
40
|
-
apiBaseUrl={runtimeConfig.authApi}
|
|
41
|
-
authUrl={runtimeConfig.authorizeUrl}
|
|
42
|
-
components={{ LoadingScreen: AppLoader, ErrorScreen: AppAuthError }}
|
|
43
|
-
>
|
|
44
|
-
<App />
|
|
45
|
-
</PofsisAuth>
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
### `RequireAuth`
|
|
49
|
-
|
|
50
|
-
`RequireAuth({ children, fallback?, onUnauthenticated? })` renders authenticated content. `fallback` overrides loading UI for that guard. Without `onUnauthenticated`, an unauthenticated visitor starts login; failures route to `/auth/error`.
|
|
51
|
-
|
|
52
|
-
### `AuthLoadingScreen`
|
|
53
|
-
|
|
54
|
-
The default full-screen loader. `AuthLoadingScreenProps.callback` changes the message for login/callback work.
|
|
55
|
-
|
|
56
|
-
### `AuthErrorScreen`
|
|
57
|
-
|
|
58
|
-
The default error page. `AuthErrorScreenProps.retryHref` defaults to `/login`. Its illustration is emitted into the compiled bundle as a data asset.
|
|
59
|
-
|
|
60
|
-
## `useAuth`
|
|
61
|
-
|
|
62
|
-
`useAuth(): AuthContextValue` must be called below `PofsisAuth`.
|
|
63
|
-
|
|
64
|
-
| Value or method | Meaning |
|
|
65
|
-
| --------------------------------------- | ----------------------------------------------------------------------------- |
|
|
66
|
-
| `user` | Current `PofsisUser`, or `null` |
|
|
67
|
-
| `session` | Current `SessionPayload`, or `null` |
|
|
68
|
-
| `isAuthenticated` | Whether a session is present |
|
|
69
|
-
| `isLoading` | Whether initial session restoration is running |
|
|
70
|
-
| `login(options?)` | Starts OAuth/PKCE login |
|
|
71
|
-
| `logout()` | Ends the remote session, clears local state, broadcasts logout, and redirects |
|
|
72
|
-
| `refreshSession()` | Exchanges the refresh cookie for a new access token |
|
|
73
|
-
| `getAccessToken()` | Returns the in-memory token or `null` |
|
|
74
|
-
| `getAccountProfile()` | Fetches and merges the current `AccountProfile` |
|
|
75
|
-
| `updateAccountProfile(profile)` | Updates first and/or last name |
|
|
76
|
-
| `uploadAccountProfileImage(kind, file)` | Uploads a `profile` or `cover` image |
|
|
77
|
-
| `deleteAccountProfileImage(kind)` | Removes a `profile` or `cover` image |
|
|
78
|
-
| `completeCallback(code, state)` | Completes PKCE callback; normally used internally |
|
|
79
|
-
|
|
80
|
-
## Login options and URL hints
|
|
81
|
-
|
|
82
|
-
`login(options)` accepts `AuthLaunchOptions`:
|
|
83
|
-
|
|
84
|
-
- `returnUrl`: accepted only when it starts with `/` and not `//`; unsafe or external values are discarded.
|
|
85
|
-
- `screen`: `login`, `signup`, or `reset`; legacy `register` is normalized to `signup`.
|
|
86
|
-
- `loginHint`: valid email or Philippine mobile number. Emails are trimmed/lowercased; mobile numbers normalize to `+63`; invalid or values over 320 characters are ignored.
|
|
87
|
-
- `method`: `password`, `passkey`, or `otp`. Login accepts all three methods. Signup accepts `password` or `otp`; OTP signup continues to the verification-code page after the identifier is submitted.
|
|
88
|
-
|
|
89
|
-
The `/login` route also reads `screen`, `login_hint`, and `method`. Legacy `email` is accepted only as an email hint and only when canonical `login_hint` is absent. Unknown values are ignored. Signup defaults to password when no method is supplied and preserves an explicit `otp`; reset does not forward a method.
|
|
90
|
-
|
|
91
|
-
Fixed paths are `/login`, `/auth/callback`, and `/auth/error`. Saved callback destinations are restricted to safe local paths.
|
|
92
|
-
|
|
93
|
-
## Axios interceptor
|
|
94
|
-
|
|
95
|
-
`attachAuthInterceptor(client, getToken, refresh)` adds the current bearer token and performs one refresh-and-retry after a 401. It returns a cleanup function that ejects both interceptors. Axios is optional unless this helper is used.
|
|
96
|
-
|
|
97
|
-
## Configuration helper
|
|
98
|
-
|
|
99
|
-
`resolveConfig(overrides: ConfigOverrides)` validates `
|
|
100
|
-
|
|
101
|
-
## Exported types
|
|
102
|
-
|
|
103
|
-
- `PofsisAuthProps`, `PofsisAuthConfig`, `ConfigOverrides`, `AuthComponentOverrides`
|
|
104
|
-
- `AuthLoadingScreenProps`, `AuthErrorScreenProps`, `RequireAuthProps`
|
|
105
|
-
- `AuthContextValue`, `AuthLaunchOptions`, `AuthScreen`, `AuthMethod`
|
|
106
|
-
- `PofsisUser`, `AccountProfile`, `SessionPayload`, `TokenResponse`
|
|
107
|
-
- `OAuthClientConfig`
|
|
108
|
-
|
|
109
|
-
`SessionPayload` contains `token_type`, `expires_in`, and `user`. `TokenResponse` adds `access_token`. Access tokens remain in memory. `PofsisUser` exposes identity, display/profile media, and optional roles. `AccountProfile` represents the editable account profile and timestamps. `OAuthClientConfig` represents server-resolved client, redirect, and logout details.
|
|
110
|
-
|
|
111
|
-
## Module formats
|
|
112
|
-
|
|
113
|
-
ESM/JavaScript and TypeScript use the same package import:
|
|
114
|
-
|
|
115
|
-
```ts
|
|
116
|
-
import { PofsisAuth, useAuth } from '@pofsis-nbt/pofsis-auth'
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
CommonJS uses:
|
|
120
|
-
|
|
121
|
-
```js
|
|
122
|
-
const { PofsisAuth, useAuth } = require('@pofsis-nbt/pofsis-auth')
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
TypeScript declarations resolve from `dist/index.d.ts`. No separate TypeScript package is needed.
|
|
126
|
-
|
|
127
|
-
## Build and verification process
|
|
128
|
-
|
|
129
|
-
```bash
|
|
130
|
-
npm run format:check
|
|
131
|
-
npm run typecheck
|
|
132
|
-
npm test
|
|
133
|
-
npm run build
|
|
134
|
-
npm run pack:check
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
`dist/` contains ESM and CommonJS JavaScript, source maps, declaration files/maps, component declarations, and `style.css`. The npm package includes only `dist`, `package.json`, `README.md`, and `Documentation.md`.
|
|
138
|
-
|
|
139
|
-
## Public boundary and migration
|
|
140
|
-
|
|
141
|
-
Supported imports are the package root and `@pofsis-nbt/pofsis-auth/style.css`. Files under `auth/`, `components/`, `context/`, `src/`, and `dist/` are implementation details and are not exported.
|
|
142
|
-
|
|
143
|
-
Migrating from `@pofsis/auth-react` requires changing the package name, passing explicit provider configuration, and importing the stylesheet. OAuth paths, PKCE/session behavior, hooks, profile methods, UI overrides, and interceptor behavior remain available.
|
|
1
|
+
# POFSIS Auth Documentation
|
|
2
|
+
|
|
3
|
+
This is the complete public API and integration reference for `@pofsis-nbt/pofsis-auth@2.0.0`.
|
|
4
|
+
|
|
5
|
+
The repository also includes an interactive [POFSIS Auth documentation portal](./index.html) with required environment configuration, generated setup examples, and authentication scenario links. The portal does not persist or transmit entered values and is intentionally excluded from the npm package.
|
|
6
|
+
|
|
7
|
+
The [popup integration guide](./docs/popup-integration.md) is the canonical consumer reference for framework-neutral, React, and Web Component popup launches.
|
|
8
|
+
|
|
9
|
+
## Integration process
|
|
10
|
+
|
|
11
|
+
1. Install `@pofsis-nbt/pofsis-auth` with its React, React DOM, and optional Axios peers.
|
|
12
|
+
2. Import `@pofsis-nbt/pofsis-auth/style.css` once.
|
|
13
|
+
3. Wrap the application in `PofsisAuth` and supply runtime configuration.
|
|
14
|
+
4. Protect authenticated content with `RequireAuth` or use `useAuth` directly.
|
|
15
|
+
5. Register `/auth/callback` and the application origin with the POFSIS Auth service.
|
|
16
|
+
|
|
17
|
+
The consuming application owns environment lookup. The library never reads `import.meta.env`.
|
|
18
|
+
|
|
19
|
+
## Public components
|
|
20
|
+
|
|
21
|
+
### `PofsisAuth`
|
|
22
|
+
|
|
23
|
+
The provider restores the cookie-backed session, manages the in-memory access token, coordinates cross-tab logout, runs OAuth/PKCE, and handles fixed auth paths.
|
|
24
|
+
|
|
25
|
+
`PofsisAuthProps`:
|
|
26
|
+
|
|
27
|
+
| Prop | Type | Required | Meaning |
|
|
28
|
+
| --------------- | ------------------------ | -------- | -------------------------------------- |
|
|
29
|
+
| `children` | `ReactNode` | yes | Application content |
|
|
30
|
+
| `applicationId` | `string` | yes | Immutable `applications.id` UUID used for client discovery |
|
|
31
|
+
| `apiBaseUrl` | `string` | yes | Auth API base URL |
|
|
32
|
+
| `authUrl` | `string` | yes | OAuth authorize URL |
|
|
33
|
+
| `scope` | `string` | no | Defaults to `openid profile email` |
|
|
34
|
+
| `postLoginPath` | `string` | no | Callback destination; defaults to `/` |
|
|
35
|
+
| `components` | `AuthComponentOverrides` | no | Custom loading and error screens |
|
|
36
|
+
|
|
37
|
+
```tsx
|
|
38
|
+
<PofsisAuth
|
|
39
|
+
applicationId="11111111-1111-4111-8111-111111111111"
|
|
40
|
+
apiBaseUrl={runtimeConfig.authApi}
|
|
41
|
+
authUrl={runtimeConfig.authorizeUrl}
|
|
42
|
+
components={{ LoadingScreen: AppLoader, ErrorScreen: AppAuthError }}
|
|
43
|
+
>
|
|
44
|
+
<App />
|
|
45
|
+
</PofsisAuth>
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### `RequireAuth`
|
|
49
|
+
|
|
50
|
+
`RequireAuth({ children, fallback?, onUnauthenticated? })` renders authenticated content. `fallback` overrides loading UI for that guard. Without `onUnauthenticated`, an unauthenticated visitor starts login; failures route to `/auth/error`.
|
|
51
|
+
|
|
52
|
+
### `AuthLoadingScreen`
|
|
53
|
+
|
|
54
|
+
The default full-screen loader. `AuthLoadingScreenProps.callback` changes the message for login/callback work.
|
|
55
|
+
|
|
56
|
+
### `AuthErrorScreen`
|
|
57
|
+
|
|
58
|
+
The default error page. `AuthErrorScreenProps.retryHref` defaults to `/login`. Its illustration is emitted into the compiled bundle as a data asset.
|
|
59
|
+
|
|
60
|
+
## `useAuth`
|
|
61
|
+
|
|
62
|
+
`useAuth(): AuthContextValue` must be called below `PofsisAuth`.
|
|
63
|
+
|
|
64
|
+
| Value or method | Meaning |
|
|
65
|
+
| --------------------------------------- | ----------------------------------------------------------------------------- |
|
|
66
|
+
| `user` | Current `PofsisUser`, or `null` |
|
|
67
|
+
| `session` | Current `SessionPayload`, or `null` |
|
|
68
|
+
| `isAuthenticated` | Whether a session is present |
|
|
69
|
+
| `isLoading` | Whether initial session restoration is running |
|
|
70
|
+
| `login(options?)` | Starts OAuth/PKCE login |
|
|
71
|
+
| `logout()` | Ends the remote session, clears local state, broadcasts logout, and redirects |
|
|
72
|
+
| `refreshSession()` | Exchanges the refresh cookie for a new access token |
|
|
73
|
+
| `getAccessToken()` | Returns the in-memory token or `null` |
|
|
74
|
+
| `getAccountProfile()` | Fetches and merges the current `AccountProfile` |
|
|
75
|
+
| `updateAccountProfile(profile)` | Updates first and/or last name |
|
|
76
|
+
| `uploadAccountProfileImage(kind, file)` | Uploads a `profile` or `cover` image |
|
|
77
|
+
| `deleteAccountProfileImage(kind)` | Removes a `profile` or `cover` image |
|
|
78
|
+
| `completeCallback(code, state)` | Completes PKCE callback; normally used internally |
|
|
79
|
+
|
|
80
|
+
## Login options and URL hints
|
|
81
|
+
|
|
82
|
+
`login(options)` accepts `AuthLaunchOptions`:
|
|
83
|
+
|
|
84
|
+
- `returnUrl`: accepted only when it starts with `/` and not `//`; unsafe or external values are discarded.
|
|
85
|
+
- `screen`: `login`, `signup`, or `reset`; legacy `register` is normalized to `signup`.
|
|
86
|
+
- `loginHint`: valid email or Philippine mobile number. Emails are trimmed/lowercased; mobile numbers normalize to `+63`; invalid or values over 320 characters are ignored.
|
|
87
|
+
- `method`: `password`, `passkey`, or `otp`. Login accepts all three methods. Signup accepts `password` or `otp`; OTP signup continues to the verification-code page after the identifier is submitted.
|
|
88
|
+
|
|
89
|
+
The `/login` route also reads `screen`, `login_hint`, and `method`. Legacy `email` is accepted only as an email hint and only when canonical `login_hint` is absent. Unknown values are ignored. Signup defaults to password when no method is supplied and preserves an explicit `otp`; reset does not forward a method.
|
|
90
|
+
|
|
91
|
+
Fixed paths are `/login`, `/auth/callback`, and `/auth/error`. Saved callback destinations are restricted to safe local paths.
|
|
92
|
+
|
|
93
|
+
## Axios interceptor
|
|
94
|
+
|
|
95
|
+
`attachAuthInterceptor(client, getToken, refresh)` adds the current bearer token and performs one refresh-and-retry after a 401. It returns a cleanup function that ejects both interceptors. Axios is optional unless this helper is used.
|
|
96
|
+
|
|
97
|
+
## Configuration helper
|
|
98
|
+
|
|
99
|
+
`resolveConfig(overrides: ConfigOverrides)` validates `applicationId`, `apiBaseUrl`, and `authUrl`, trims values, removes a trailing slash from URLs, and supplies the default scope. Missing required values throw synchronously.
|
|
100
|
+
|
|
101
|
+
## Exported types
|
|
102
|
+
|
|
103
|
+
- `PofsisAuthProps`, `PofsisAuthConfig`, `ConfigOverrides`, `AuthComponentOverrides`
|
|
104
|
+
- `AuthLoadingScreenProps`, `AuthErrorScreenProps`, `RequireAuthProps`
|
|
105
|
+
- `AuthContextValue`, `AuthLaunchOptions`, `AuthScreen`, `AuthMethod`
|
|
106
|
+
- `PofsisUser`, `AccountProfile`, `SessionPayload`, `TokenResponse`
|
|
107
|
+
- `OAuthClientConfig`
|
|
108
|
+
|
|
109
|
+
`SessionPayload` contains `token_type`, `expires_in`, and `user`. `TokenResponse` adds `access_token`. Access tokens remain in memory. `PofsisUser` exposes identity, display/profile media, and optional roles. `AccountProfile` represents the editable account profile and timestamps. `OAuthClientConfig` represents server-resolved client, redirect, and logout details.
|
|
110
|
+
|
|
111
|
+
## Module formats
|
|
112
|
+
|
|
113
|
+
ESM/JavaScript and TypeScript use the same package import:
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
import { PofsisAuth, useAuth } from '@pofsis-nbt/pofsis-auth'
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
CommonJS uses:
|
|
120
|
+
|
|
121
|
+
```js
|
|
122
|
+
const { PofsisAuth, useAuth } = require('@pofsis-nbt/pofsis-auth')
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
TypeScript declarations resolve from `dist/index.d.ts`. No separate TypeScript package is needed.
|
|
126
|
+
|
|
127
|
+
## Build and verification process
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
npm run format:check
|
|
131
|
+
npm run typecheck
|
|
132
|
+
npm test
|
|
133
|
+
npm run build
|
|
134
|
+
npm run pack:check
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
`dist/` contains ESM and CommonJS JavaScript, source maps, declaration files/maps, component declarations, and `style.css`. The npm package includes only `dist`, `package.json`, `README.md`, and `Documentation.md`.
|
|
138
|
+
|
|
139
|
+
## Public boundary and migration
|
|
140
|
+
|
|
141
|
+
Supported imports are the package root and `@pofsis-nbt/pofsis-auth/style.css`. Files under `auth/`, `components/`, `context/`, `src/`, and `dist/` are implementation details and are not exported.
|
|
142
|
+
|
|
143
|
+
Migrating from `@pofsis/auth-react` requires changing the package name, passing explicit provider configuration, and importing the stylesheet. OAuth paths, PKCE/session behavior, hooks, profile methods, UI overrides, and interceptor behavior remain available.
|
package/README.md
CHANGED
|
@@ -1,130 +1,130 @@
|
|
|
1
|
-
# @pofsis-nbt/pofsis-auth
|
|
2
|
-
|
|
3
|
-
React OAuth 2.0/PKCE authentication for POFSIS applications. One package serves JavaScript and TypeScript consumers through ESM, CommonJS, generated declarations, and extracted CSS.
|
|
4
|
-
|
|
5
|
-
For guided setup and authentication scenarios, open the repository's interactive [POFSIS Auth documentation portal](./index.html). It validates consumer-supplied environment values and generates safe `/login` launch links without storing them.
|
|
6
|
-
|
|
7
|
-
For hosted popup setup, parameters, callback handling, React usage, and the optional Web Component, see the [popup integration guide](./docs/popup-integration.md).
|
|
8
|
-
|
|
9
|
-
## Install
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
npm install @pofsis-nbt/pofsis-auth axios react react-dom
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
Import the package stylesheet once in the application entry point:
|
|
16
|
-
|
|
17
|
-
```ts
|
|
18
|
-
import '@pofsis-nbt/pofsis-auth/style.css'
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
## Quick start
|
|
22
|
-
|
|
23
|
-
```tsx
|
|
24
|
-
import { PofsisAuth, RequireAuth } from '@pofsis-nbt/pofsis-auth'
|
|
25
|
-
import '@pofsis-nbt/pofsis-auth/style.css'
|
|
26
|
-
|
|
27
|
-
export function App() {
|
|
28
|
-
return (
|
|
29
|
-
<PofsisAuth
|
|
30
|
-
|
|
31
|
-
apiBaseUrl="https://auth-api.example.com"
|
|
32
|
-
authUrl="https://auth.example.com/authorize"
|
|
33
|
-
>
|
|
34
|
-
<RequireAuth>
|
|
35
|
-
<Dashboard />
|
|
36
|
-
</RequireAuth>
|
|
37
|
-
</PofsisAuth>
|
|
38
|
-
)
|
|
39
|
-
}
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
`
|
|
43
|
-
|
|
44
|
-
```tsx
|
|
45
|
-
<PofsisAuth
|
|
46
|
-
|
|
47
|
-
apiBaseUrl={import.meta.env.VITE_POFSIS_API_BASE_URL}
|
|
48
|
-
authUrl={import.meta.env.VITE_POFSIS_AUTH_URL}
|
|
49
|
-
scope={import.meta.env.VITE_POFSIS_SCOPE}
|
|
50
|
-
>
|
|
51
|
-
<App />
|
|
52
|
-
</PofsisAuth>
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
The same props may come from server-injected runtime configuration or hardcoded deployment configuration. The default scope is `openid profile email`.
|
|
56
|
-
|
|
57
|
-
## Session and login
|
|
58
|
-
|
|
59
|
-
```tsx
|
|
60
|
-
import { useAuth } from '@pofsis-nbt/pofsis-auth'
|
|
61
|
-
|
|
62
|
-
function AccountMenu() {
|
|
63
|
-
const { user, login, logout } = useAuth()
|
|
64
|
-
if (!user) return <button onClick={() => void login()}>Sign in</button>
|
|
65
|
-
return <button onClick={() => void logout()}>Sign out {user.displayName}</button>
|
|
66
|
-
}
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
Explicit user actions open hosted Auth in a popup:
|
|
70
|
-
|
|
71
|
-
```tsx
|
|
72
|
-
const { login } = useAuth()
|
|
73
|
-
<button onClick={() => void login({ presentation: 'popup', returnUrl: location.pathname })}>
|
|
74
|
-
Sign in
|
|
75
|
-
</button>
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
The provider handles `/login`, `/auth/callback`, and `/auth/error`. Login supports `screen`, `loginHint`, `method`, and a safe application-relative `returnUrl`. An OTP signup opens the signup page and continues to account verification after the identifier is submitted. See [Documentation.md](./Documentation.md) for the complete API.
|
|
79
|
-
|
|
80
|
-
## Axios
|
|
81
|
-
|
|
82
|
-
```ts
|
|
83
|
-
import axios from 'axios'
|
|
84
|
-
import { attachAuthInterceptor, useAuth } from '@pofsis-nbt/pofsis-auth'
|
|
85
|
-
|
|
86
|
-
const api = axios.create({ baseURL: '/api' })
|
|
87
|
-
|
|
88
|
-
function ApiAuthBridge() {
|
|
89
|
-
const { getAccessToken, refreshSession } = useAuth()
|
|
90
|
-
React.useEffect(
|
|
91
|
-
() => attachAuthInterceptor(api, getAccessToken, refreshSession),
|
|
92
|
-
[getAccessToken, refreshSession],
|
|
93
|
-
)
|
|
94
|
-
return null
|
|
95
|
-
}
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
## CommonJS
|
|
99
|
-
|
|
100
|
-
```js
|
|
101
|
-
const { PofsisAuth, RequireAuth, useAuth } = require('@pofsis-nbt/pofsis-auth')
|
|
102
|
-
require('@pofsis-nbt/pofsis-auth/style.css')
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
JavaScript consumers use the compiled JavaScript. TypeScript consumers use the same imports and automatically receive declarations.
|
|
106
|
-
|
|
107
|
-
## Development
|
|
108
|
-
|
|
109
|
-
Requires Node `^20.19.0` or `>=22.12.0`.
|
|
110
|
-
|
|
111
|
-
```bash
|
|
112
|
-
npm install
|
|
113
|
-
npm run format:check
|
|
114
|
-
npm run typecheck
|
|
115
|
-
npm test
|
|
116
|
-
npm run build
|
|
117
|
-
npm run pack:check
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
Build output is written to `dist/` with ESM (`index.js`), CommonJS (`index.cjs`), source maps, declarations, and `style.css`.
|
|
121
|
-
|
|
122
|
-
## Migration
|
|
123
|
-
|
|
124
|
-
When migrating from `@pofsis/auth-react`:
|
|
125
|
-
|
|
126
|
-
1. Change imports to `@pofsis-nbt/pofsis-auth`.
|
|
127
|
-
2. Pass `
|
|
128
|
-
3. Import `@pofsis-nbt/pofsis-auth/style.css` once.
|
|
129
|
-
|
|
130
|
-
Do not import `src/`, `dist/` internals, or internal auth helpers. Only the package-root exports and `style.css` are supported.
|
|
1
|
+
# @pofsis-nbt/pofsis-auth
|
|
2
|
+
|
|
3
|
+
React OAuth 2.0/PKCE authentication for POFSIS applications. One package serves JavaScript and TypeScript consumers through ESM, CommonJS, generated declarations, and extracted CSS.
|
|
4
|
+
|
|
5
|
+
For guided setup and authentication scenarios, open the repository's interactive [POFSIS Auth documentation portal](./index.html). It validates consumer-supplied environment values and generates safe `/login` launch links without storing them.
|
|
6
|
+
|
|
7
|
+
For hosted popup setup, parameters, callback handling, React usage, and the optional Web Component, see the [popup integration guide](./docs/popup-integration.md).
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @pofsis-nbt/pofsis-auth axios react react-dom
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Import the package stylesheet once in the application entry point:
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import '@pofsis-nbt/pofsis-auth/style.css'
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Quick start
|
|
22
|
+
|
|
23
|
+
```tsx
|
|
24
|
+
import { PofsisAuth, RequireAuth } from '@pofsis-nbt/pofsis-auth'
|
|
25
|
+
import '@pofsis-nbt/pofsis-auth/style.css'
|
|
26
|
+
|
|
27
|
+
export function App() {
|
|
28
|
+
return (
|
|
29
|
+
<PofsisAuth
|
|
30
|
+
applicationId="11111111-1111-4111-8111-111111111111"
|
|
31
|
+
apiBaseUrl="https://auth-api.example.com"
|
|
32
|
+
authUrl="https://auth.example.com/authorize"
|
|
33
|
+
>
|
|
34
|
+
<RequireAuth>
|
|
35
|
+
<Dashboard />
|
|
36
|
+
</RequireAuth>
|
|
37
|
+
</PofsisAuth>
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
`applicationId`, `apiBaseUrl`, and `authUrl` are required. The library does not read environment variables. A Vite application may pass its own values:
|
|
43
|
+
|
|
44
|
+
```tsx
|
|
45
|
+
<PofsisAuth
|
|
46
|
+
applicationId={import.meta.env.VITE_POFSIS_APPLICATION_ID}
|
|
47
|
+
apiBaseUrl={import.meta.env.VITE_POFSIS_API_BASE_URL}
|
|
48
|
+
authUrl={import.meta.env.VITE_POFSIS_AUTH_URL}
|
|
49
|
+
scope={import.meta.env.VITE_POFSIS_SCOPE}
|
|
50
|
+
>
|
|
51
|
+
<App />
|
|
52
|
+
</PofsisAuth>
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
The same props may come from server-injected runtime configuration or hardcoded deployment configuration. The default scope is `openid profile email`.
|
|
56
|
+
|
|
57
|
+
## Session and login
|
|
58
|
+
|
|
59
|
+
```tsx
|
|
60
|
+
import { useAuth } from '@pofsis-nbt/pofsis-auth'
|
|
61
|
+
|
|
62
|
+
function AccountMenu() {
|
|
63
|
+
const { user, login, logout } = useAuth()
|
|
64
|
+
if (!user) return <button onClick={() => void login()}>Sign in</button>
|
|
65
|
+
return <button onClick={() => void logout()}>Sign out {user.displayName}</button>
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Explicit user actions open hosted Auth in a popup:
|
|
70
|
+
|
|
71
|
+
```tsx
|
|
72
|
+
const { login } = useAuth()
|
|
73
|
+
<button onClick={() => void login({ presentation: 'popup', returnUrl: location.pathname })}>
|
|
74
|
+
Sign in
|
|
75
|
+
</button>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
The provider handles `/login`, `/auth/callback`, and `/auth/error`. Login supports `screen`, `loginHint`, `method`, and a safe application-relative `returnUrl`. An OTP signup opens the signup page and continues to account verification after the identifier is submitted. See [Documentation.md](./Documentation.md) for the complete API.
|
|
79
|
+
|
|
80
|
+
## Axios
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
import axios from 'axios'
|
|
84
|
+
import { attachAuthInterceptor, useAuth } from '@pofsis-nbt/pofsis-auth'
|
|
85
|
+
|
|
86
|
+
const api = axios.create({ baseURL: '/api' })
|
|
87
|
+
|
|
88
|
+
function ApiAuthBridge() {
|
|
89
|
+
const { getAccessToken, refreshSession } = useAuth()
|
|
90
|
+
React.useEffect(
|
|
91
|
+
() => attachAuthInterceptor(api, getAccessToken, refreshSession),
|
|
92
|
+
[getAccessToken, refreshSession],
|
|
93
|
+
)
|
|
94
|
+
return null
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## CommonJS
|
|
99
|
+
|
|
100
|
+
```js
|
|
101
|
+
const { PofsisAuth, RequireAuth, useAuth } = require('@pofsis-nbt/pofsis-auth')
|
|
102
|
+
require('@pofsis-nbt/pofsis-auth/style.css')
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
JavaScript consumers use the compiled JavaScript. TypeScript consumers use the same imports and automatically receive declarations.
|
|
106
|
+
|
|
107
|
+
## Development
|
|
108
|
+
|
|
109
|
+
Requires Node `^20.19.0` or `>=22.12.0`.
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
npm install
|
|
113
|
+
npm run format:check
|
|
114
|
+
npm run typecheck
|
|
115
|
+
npm test
|
|
116
|
+
npm run build
|
|
117
|
+
npm run pack:check
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Build output is written to `dist/` with ESM (`index.js`), CommonJS (`index.cjs`), source maps, declarations, and `style.css`.
|
|
121
|
+
|
|
122
|
+
## Migration
|
|
123
|
+
|
|
124
|
+
When migrating from `@pofsis/auth-react`:
|
|
125
|
+
|
|
126
|
+
1. Change imports to `@pofsis-nbt/pofsis-auth`.
|
|
127
|
+
2. Pass `applicationId`, `apiBaseUrl`, and `authUrl` to `PofsisAuth`.
|
|
128
|
+
3. Import `@pofsis-nbt/pofsis-auth/style.css` once.
|
|
129
|
+
|
|
130
|
+
Do not import `src/`, `dist/` internals, or internal auth helpers. Only the package-root exports and `style.css` are supported.
|
package/dist/PofsisAuth.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { PofsisAuthProps } from './types';
|
|
2
|
-
export declare function PofsisAuth({ children,
|
|
2
|
+
export declare function PofsisAuth({ children, applicationId, apiBaseUrl, authUrl, scope, callbackPath, popup, postLoginPath, components, }: PofsisAuthProps): import("react").JSX.Element;
|
|
3
3
|
//# sourceMappingURL=PofsisAuth.d.ts.map
|
package/dist/PofsisAuth.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PofsisAuth.d.ts","sourceRoot":"","sources":["../src/PofsisAuth.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAGR,eAAe,EAGlB,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"PofsisAuth.d.ts","sourceRoot":"","sources":["../src/PofsisAuth.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAGR,eAAe,EAGlB,MAAM,SAAS,CAAA;AAgMhB,wBAAgB,UAAU,CAAC,EACvB,QAAQ,EACR,aAAa,EACb,UAAU,EACV,OAAO,EACP,KAAK,EACL,YAAY,EACZ,KAAK,EACL,aAAmB,EACnB,UAAU,GACb,EAAE,eAAe,+BAiCjB"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
async function e(e){if(e.status===204)return null;let t=await e.text();return t?JSON.parse(t):null}async function t(t,n,r){let i=await fetch(`${t.apiBaseUrl}${n}`,{credentials:`include`,...r,headers:{Accept:`application/json`,...r?.body&&!(r.body instanceof FormData)?{"Content-Type":`application/json`}:{},...r?.headers}});if(!i.ok){let e=Error(`Auth API ${n} failed (${i.status})`);throw e.status=i.status,e}return{status:i.status,data:await e(i)}}async function n(e){let{data:n}=await t(e,`/oauth/applications/${encodeURIComponent(e.applicationId)}/client?origin=${encodeURIComponent(window.location.origin)}`);return n}async function r(e,n,r,i){let{data:a}=await t(e,`/oauth/token`,{method:`POST`,body:JSON.stringify({grant_type:`authorization_code`,client_id:i.client_id,redirect_uri:i.redirect_uri,code:n,code_verifier:r})});return a}async function i(e,n){let{data:r}=await t(e,`/oauth/token`,{method:`POST`,body:JSON.stringify({grant_type:`refresh_token`,client_id:n})});return r||null}async function a(e){try{return await t(e,`/auth/session`),!0}catch{return!1}}async function o(e){await t(e,`/auth/logout`,{method:`POST`})}async function s(e,n){let{data:r}=await t(e,`/auth/profile/me`,{headers:{Authorization:`Bearer ${n}`}});return r}async function c(e,n,r){let{data:i}=await t(e,`/auth/profile/me`,{method:`PATCH`,headers:{Authorization:`Bearer ${n}`},body:JSON.stringify(r)});return i}async function l(e,n,r,i){let a=new FormData;a.append(`file`,i);let{data:o}=await t(e,`/auth/profile/me/images/${r}`,{method:`POST`,headers:{Authorization:`Bearer ${n}`},body:a});return o}async function u(e,n,r){let{data:i}=await t(e,`/auth/profile/me/images/${r}`,{method:`DELETE`,headers:{Authorization:`Bearer ${n}`}});return i}function d(e){return e.replace(/\/$/,``)}function f(e={}){let t=e.applicationId?.trim(),n=e.apiBaseUrl?.trim(),r=e.authUrl?.trim(),i=e.scope?.trim()||`openid profile email`,a=e.callbackPath?.trim()||`/auth/callback`,o={width:e.popup?.width??480,height:e.popup?.height??720,name:e.popup?.name?.trim()||`pofsis-auth`,timeoutMs:e.popup?.timeoutMs??3e5},s=[];if(t||s.push(`applicationId`),n||s.push(`apiBaseUrl`),r||s.push(`authUrl`),s.length)throw Error(`@pofsis-nbt/pofsis-auth missing config: ${s.join(`, `)}`);if(!t||!n||!r)throw Error(`@pofsis-nbt/pofsis-auth missing config`);if(!/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(t))throw Error(`@pofsis-nbt/pofsis-auth applicationId must be a UUID`);if(!a.startsWith(`/`)||a.startsWith(`//`))throw Error(`@pofsis-nbt/pofsis-auth callbackPath must be application-relative`);if(o.width<=0||o.height<=0||o.timeoutMs<=0)throw Error(`@pofsis-nbt/pofsis-auth popup dimensions and timeout must be positive`);return{applicationId:t.toLowerCase(),apiBaseUrl:d(n),authUrl:d(r),scope:i,callbackPath:a,popup:o}}var p=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,m=/^(?:\+63|63|0)?9\d{9}$/,h=new Set([`password`,`passkey`,`otp`]),g=new Set([`login`,`signup`,`reset`]),_=320;function v(e,t=!1){let n=typeof e==`string`?e.trim():``;if(!n||n.length>_)return;if(p.test(n))return n.toLowerCase();let r=n.replace(/[\s()-]/g,``);if(!t&&m.test(r))return`+63${r.replace(/^(?:\+63|63|0)/,``)}`}function y(e,t=`login`){let n=typeof e==`string`?{returnUrl:e}:e||{},r=n.screen===`register`?`signup`:n.screen,i=g.has(r)?r:t,a=h.has(n.method)?n.method:void 0,o=i===`login`||i===`signup`&&(a===`password`||a===`otp`)?a:void 0;return{returnUrl:n.returnUrl,screen:i,loginHint:v(n.loginHint),method:o}}function b(e){let t=new URLSearchParams(e),n=t.get(`login_hint`),r=n===null?v(t.get(`email`),!0):v(n);return y({screen:t.get(`screen`)||void 0,loginHint:r,method:t.get(`method`)||void 0})}function x({authUrl:e,query:t,options:n}){let r=y(n),i=new URL(e);if(i.search=t.toString(),r.loginHint&&i.searchParams.set(`login_hint`,r.loginHint),r.screen===`login`&&r.method&&i.searchParams.set(`method`,r.method),r.screen===`login`)return i.toString();let a=r.screen===`signup`?`/signup`:`/forgot-password`,o=new URL(a,i),s=t.get(`client_id`);return s&&o.searchParams.set(`client_id`,s),o.searchParams.set(`return_to`,`${i.pathname}${i.search}`),r.loginHint&&o.searchParams.set(`login_hint`,r.loginHint),r.screen===`signup`&&o.searchParams.set(`method`,r.method||`password`),o.toString()}var S=`pofsis-auth:callback`;function C(e){if(!e)return;let t=e.indexOf(`.`);return t>0?e.slice(0,t):void 0}function w(e=window.location.origin){if(!window.opener||window.opener.closed)return!1;let t=new URLSearchParams(window.location.search),n=t.get(`state`)||void 0,r={type:S,code:t.get(`code`)||void 0,state:n,error:t.get(`error`)||void 0,correlationId:C(n||null)};return window.opener.postMessage(r,e),window.close(),!0}var T=e=>btoa(String.fromCharCode(...e)).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``),E=()=>T(crypto.getRandomValues(new Uint8Array(32)));async function D(e){return T(new Uint8Array(await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(e))))}var O=e=>e?.startsWith(`/`)&&!e.startsWith(`//`)?e:void 0,k=e=>({token_type:e.token_type,expires_in:e.expires_in,user:e.user}),A=class{config;token=null;session=null;client=null;clientPromise=null;refreshPromise=null;subscribers=new Set;attempt=null;listening=!1;constructor(e){this.config=f(e),this.attach()}attach(){this.listening||=(window.addEventListener(`message`,this.onPopupMessage),!0)}destroy(){window.removeEventListener(`message`,this.onPopupMessage),this.listening=!1;let e=this.finishAttempt();e&&(e.popup.close(),e.resolve({status:`cancelled`})),this.subscribers.clear()}getUser(){return this.session?.user??null}getSession(){return this.session}getAccessToken(){return this.token}subscribe(e){return this.attach(),this.subscribers.add(e),e(this.session),()=>{this.subscribers.delete(e)}}emit(){for(let e of this.subscribers)e(this.session)}accept(e){this.token=e.access_token,this.session=k(e),this.emit()}loadClient(){return this.clientPromise||=n(this.config).then(e=>this.client=e).catch(e=>{throw this.clientPromise=null,e}),this.clientPromise}getOAuthClient(){return this.loadClient()}async refreshSession(){let e=await this.loadClient();return this.refreshPromise||=i(this.config,e.client_id).then(e=>{e?this.accept(e):this.clearSession()}).finally(()=>this.refreshPromise=null),this.refreshPromise}async isRemoteSessionActive(){return a(this.config)}clearSession(){this.token=null,this.session=null,this.emit()}replaceUser(e){this.session&&(this.session={...this.session,user:e},this.emit())}async logout(){try{await o(this.config)}finally{this.clearSession()}}signup(e={}){return this.login({...e,screen:`signup`})}resetPassword(e={}){return this.login({...e,screen:`reset`})}async login(e={}){let t=y(e);return(e.presentation??`popup`)===`popup`?this.openPopup({...e,...t}):this.startRedirect({...e,...t})}async authorizationUrl(e,t,n){let r=await this.loadClient(),i=new URLSearchParams({client_id:r.client_id,redirect_uri:r.redirect_uri,response_type:`code`,scope:this.config.scope,state:t,code_challenge:await D(n),code_challenge_method:`S256`});return x({authUrl:this.config.authUrl,query:i,options:e})}storageKey(e){return`${this.config.applicationId}.auth.${e}`}async startRedirect(e){let t=E(),n=E();sessionStorage.setItem(this.storageKey(`state`),t),sessionStorage.setItem(this.storageKey(`verifier`),n);let r=O(e.returnUrl);return r?sessionStorage.setItem(this.storageKey(`return-path`),r):sessionStorage.removeItem(this.storageKey(`return-path`)),window.location.assign(await this.authorizationUrl(e,t,n)),{status:`redirecting`}}async openPopup(e){if(this.attempt&&!this.attempt.popup.closed)return this.attempt.popup.focus(),new Promise((e,t)=>{let n=this.attempt,r=n.resolve,i=n.reject;n.resolve=t=>{r(t),e(t)},n.reject=e=>{i(e),t(e)}});let{width:t,height:n,name:r,timeoutMs:i}=this.config.popup,a=Math.max(0,window.screenX+(window.outerWidth-t)/2),o=Math.max(0,window.screenY+(window.outerHeight-n)/2),s=window.open(`about:blank`,r,`popup=yes,width=${t},height=${n},left=${Math.round(a)},top=${Math.round(o)}`);if(!s)return this.startRedirect({...e,presentation:`redirect`});let c=E(),l=`${c}.${E()}`,u=E(),d=O(e.returnUrl);return new Promise((t,n)=>{let r=setInterval(()=>{s.closed&&this.finishAttempt()?.resolve({status:`cancelled`})},250),a=setTimeout(()=>{let e=this.finishAttempt();s.close(),e?.reject(Error(`POFSIS Auth popup timed out.`))},i);this.attempt={popup:s,state:l,verifier:u,correlationId:c,returnUrl:d,resolve:t,reject:n,timer:r,timeout:a},this.authorizationUrl(e,l,u).then(e=>s.location.replace(e)).catch(e=>{let t=this.finishAttempt();s.close(),t?.reject(e instanceof Error?e:Error(String(e)))})})}finishAttempt(){let e=this.attempt;return e?(clearInterval(e.timer),clearTimeout(e.timeout),this.attempt=null,e):null}onPopupMessage=e=>{let t=this.attempt,n=e.data;if(!t||e.origin!==window.location.origin||e.source!==t.popup||n?.type!==`pofsis-auth:callback`||n.correlationId!==t.correlationId||C(n.state||null)!==t.correlationId||n.state!==t.state)return;let r=this.finishAttempt();if(r){if(n.error||!n.code){r.popup.close(),r.reject(Error(n.error||`POFSIS Auth callback was incomplete.`));return}this.completeCode(n.code,n.state,r.verifier).then(()=>{r.popup.close(),r.returnUrl&&window.history.replaceState(null,``,r.returnUrl),r.resolve({status:`authenticated`,user:this.getUser()})}).catch(e=>{r.popup.close(),r.reject(e instanceof Error?e:Error(String(e)))})}};async completeCode(e,t,n){if(!t||!n)throw Error(`Authentication state could not be verified.`);let i=await this.loadClient();this.accept(await r(this.config,e,n,i))}async completeRedirectCallback(e,t){let n=sessionStorage.getItem(this.storageKey(`state`)),r=sessionStorage.getItem(this.storageKey(`verifier`));if(sessionStorage.removeItem(this.storageKey(`state`)),sessionStorage.removeItem(this.storageKey(`verifier`)),!n||!r||t!==n)throw Error(`Authentication state could not be verified.`);await this.completeCode(e,t,r)}};function j(e){return new A(e)}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return j}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return A}});
|
|
2
|
+
//# sourceMappingURL=PofsisAuthClient-B3YHqgZL.cjs.map
|