@authu/react 0.1.21 → 1.0.10
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/README.md +10 -0
- package/dist/AuthUProvider.d.ts.map +1 -1
- package/dist/AuthUProvider.js +8 -4
- package/dist/pkce.js +9 -9
- package/package.json +10 -9
package/README.md
CHANGED
|
@@ -164,6 +164,16 @@ pnpm publish --access public
|
|
|
164
164
|
|
|
165
165
|
The `--access public` flag is required for scoped packages.
|
|
166
166
|
|
|
167
|
+
## Changelog
|
|
168
|
+
|
|
169
|
+
### 1.0.10
|
|
170
|
+
|
|
171
|
+
- **Fix**: Changed PKCE storage from `sessionStorage` to `localStorage` to prevent state/code_verifier loss during cross-domain OAuth redirects
|
|
172
|
+
|
|
173
|
+
### 1.0.9
|
|
174
|
+
|
|
175
|
+
- Initial stable release
|
|
176
|
+
|
|
167
177
|
## License
|
|
168
178
|
|
|
169
179
|
MIT
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthUProvider.d.ts","sourceRoot":"","sources":["../src/AuthUProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EACV,WAAW,EACX,iBAAiB,EAGlB,MAAM,YAAY,CAAC;AAgBpB,eAAO,MAAM,YAAY,mDAAgD,CAAC;
|
|
1
|
+
{"version":3,"file":"AuthUProvider.d.ts","sourceRoot":"","sources":["../src/AuthUProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EACV,WAAW,EACX,iBAAiB,EAGlB,MAAM,YAAY,CAAC;AAgBpB,eAAO,MAAM,YAAY,mDAAgD,CAAC;AAO1E,UAAU,kBAAkB;IAC1B,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAID,wBAAgB,aAAa,CAAC,EAAC,MAAM,EAAE,QAAQ,EAAC,EAAE,kBAAkB,2CA+SnE"}
|
package/dist/AuthUProvider.js
CHANGED
|
@@ -2,6 +2,10 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { createContext, useEffect, useState, useCallback } from 'react';
|
|
3
3
|
import { generateCodeVerifier, generateCodeChallenge, generateState, generateNonce, storeCodeVerifier, storeState, storeNonce, getCodeVerifier, getStoredState, clearCodeVerifier, clearState, clearNonce } from './pkce.js';
|
|
4
4
|
export const AuthUContext = createContext(null);
|
|
5
|
+
function buildBaseUrl(domain) {
|
|
6
|
+
const protocol = domain.startsWith('localhost') ? 'http' : 'https';
|
|
7
|
+
return `${protocol}://${domain}`;
|
|
8
|
+
}
|
|
5
9
|
const TOKEN_STORAGE_KEY = 'authu_tokens';
|
|
6
10
|
export function AuthUProvider({ config, children }) {
|
|
7
11
|
const [state, setState] = useState({
|
|
@@ -31,14 +35,14 @@ export function AuthUProvider({ config, children }) {
|
|
|
31
35
|
code_challenge: codeChallenge,
|
|
32
36
|
code_challenge_method: 'S256'
|
|
33
37
|
});
|
|
34
|
-
return
|
|
38
|
+
return `${buildBaseUrl(config.domain)}/authorize?${params.toString()}`;
|
|
35
39
|
}, [config]);
|
|
36
40
|
const exchangeCodeForTokens = useCallback(async (code) => {
|
|
37
41
|
const codeVerifier = getCodeVerifier();
|
|
38
42
|
if (!codeVerifier) {
|
|
39
43
|
throw new Error('No code verifier found');
|
|
40
44
|
}
|
|
41
|
-
const response = await fetch(
|
|
45
|
+
const response = await fetch(`${buildBaseUrl(config.domain)}/oauth/token`, {
|
|
42
46
|
method: 'POST',
|
|
43
47
|
headers: { 'Content-Type': 'application/json' },
|
|
44
48
|
body: JSON.stringify({
|
|
@@ -91,7 +95,7 @@ export function AuthUProvider({ config, children }) {
|
|
|
91
95
|
}, []);
|
|
92
96
|
const fetchUserInfo = useCallback(async (accessToken) => {
|
|
93
97
|
try {
|
|
94
|
-
const response = await fetch(
|
|
98
|
+
const response = await fetch(`${buildBaseUrl(config.domain)}/oauth/userinfo`, {
|
|
95
99
|
headers: { Authorization: `Bearer ${accessToken}` }
|
|
96
100
|
});
|
|
97
101
|
if (!response.ok)
|
|
@@ -113,7 +117,7 @@ export function AuthUProvider({ config, children }) {
|
|
|
113
117
|
if (!state.refreshToken)
|
|
114
118
|
return false;
|
|
115
119
|
try {
|
|
116
|
-
const response = await fetch(
|
|
120
|
+
const response = await fetch(`${buildBaseUrl(config.domain)}/oauth/token`, {
|
|
117
121
|
method: 'POST',
|
|
118
122
|
headers: { 'Content-Type': 'application/json' },
|
|
119
123
|
body: JSON.stringify({
|
package/dist/pkce.js
CHANGED
|
@@ -38,29 +38,29 @@ const STORAGE_KEY_VERIFIER = 'authu_code_verifier';
|
|
|
38
38
|
const STORAGE_KEY_STATE = 'authu_state';
|
|
39
39
|
const STORAGE_KEY_NONCE = 'authu_nonce';
|
|
40
40
|
export function storeCodeVerifier(verifier) {
|
|
41
|
-
|
|
41
|
+
localStorage.setItem(STORAGE_KEY_VERIFIER, verifier);
|
|
42
42
|
}
|
|
43
43
|
export function getCodeVerifier() {
|
|
44
|
-
return
|
|
44
|
+
return localStorage.getItem(STORAGE_KEY_VERIFIER);
|
|
45
45
|
}
|
|
46
46
|
export function clearCodeVerifier() {
|
|
47
|
-
|
|
47
|
+
localStorage.removeItem(STORAGE_KEY_VERIFIER);
|
|
48
48
|
}
|
|
49
49
|
export function storeState(state) {
|
|
50
|
-
|
|
50
|
+
localStorage.setItem(STORAGE_KEY_STATE, state);
|
|
51
51
|
}
|
|
52
52
|
export function getStoredState() {
|
|
53
|
-
return
|
|
53
|
+
return localStorage.getItem(STORAGE_KEY_STATE);
|
|
54
54
|
}
|
|
55
55
|
export function clearState() {
|
|
56
|
-
|
|
56
|
+
localStorage.removeItem(STORAGE_KEY_STATE);
|
|
57
57
|
}
|
|
58
58
|
export function storeNonce(nonce) {
|
|
59
|
-
|
|
59
|
+
localStorage.setItem(STORAGE_KEY_NONCE, nonce);
|
|
60
60
|
}
|
|
61
61
|
export function getStoredNonce() {
|
|
62
|
-
return
|
|
62
|
+
return localStorage.getItem(STORAGE_KEY_NONCE);
|
|
63
63
|
}
|
|
64
64
|
export function clearNonce() {
|
|
65
|
-
|
|
65
|
+
localStorage.removeItem(STORAGE_KEY_NONCE);
|
|
66
66
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@authu/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.10",
|
|
4
4
|
"description": "React SDK for AuthU - Centralized Multi-Tenant Authentication Service",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -15,6 +15,14 @@
|
|
|
15
15
|
"files": [
|
|
16
16
|
"dist"
|
|
17
17
|
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc",
|
|
20
|
+
"dev": "tsc --watch",
|
|
21
|
+
"eslint": "eslint src --cache",
|
|
22
|
+
"typecheck": "tsc --noEmit",
|
|
23
|
+
"lint": "pnpm run eslint && pnpm run typecheck",
|
|
24
|
+
"prepublishOnly": "pnpm run build"
|
|
25
|
+
},
|
|
18
26
|
"keywords": [
|
|
19
27
|
"authu",
|
|
20
28
|
"auth",
|
|
@@ -39,12 +47,5 @@
|
|
|
39
47
|
"react": "^19.0.0",
|
|
40
48
|
"typescript": "^5.7.3",
|
|
41
49
|
"typescript-eslint": "^8.44.1"
|
|
42
|
-
},
|
|
43
|
-
"scripts": {
|
|
44
|
-
"build": "tsc",
|
|
45
|
-
"dev": "tsc --watch",
|
|
46
|
-
"eslint": "eslint src --cache",
|
|
47
|
-
"typecheck": "tsc --noEmit",
|
|
48
|
-
"lint": "pnpm run eslint && pnpm run typecheck"
|
|
49
50
|
}
|
|
50
|
-
}
|
|
51
|
+
}
|