Gathering detailed insights and metrics for react-pkce-coustome
Gathering detailed insights and metrics for react-pkce-coustome
Gathering detailed insights and metrics for react-pkce-coustome
Gathering detailed insights and metrics for react-pkce-coustome
OAuth2 authentication for React, using the PKCE flow
npm install react-pkce-coustome
Typescript
Module System
Node Version
NPM Version
JavaScript (84.55%)
HTML (15.45%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
20 Stars
115 Commits
13 Forks
4 Watchers
2 Branches
2 Contributors
Updated on Feb 20, 2025
Latest Version
0.9.12
Package Id
react-pkce-coustome@0.9.12
Unpacked Size
45.70 kB
Size
14.03 kB
File Count
28
NPM Version
6.11.3
Node Version
10.16.3
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
This zero-dependency package enables React applications to use an OAuth2 provider for authentication. The OAuth2 provider must support the PKCE Spec.
(TODO: Links to resources that explain why this is a good idea / better than using the implicit flow.)
Check the live demo (source). When prompted to login, you can signup with email (use link at the bottom of the form).
https://login.u5auth.com
access_token
to authenticate e.g. calls to APIs).npm i react-pkce
First, create an auth context (and related things):
1const clientId = "8cb4904ae5581ecc2b3a1774"
2const clientSecret = "b683283462070edbac15a8fdab751ada0f501ab48a5f06aa20aee3be24eac9cc"
3const provider = "https://authenticate.u5auth.com"
4
5const {AuthContext, Authenticated, useToken} = createAuthContext({
6 clientId,
7 clientSecret, // optional, only specify if provider requires it
8 provider,
9 scopes: [ 'profile', 'otherScope' ]
10})
You probably need those in other files, so you may want to export
them:
1export { AuthContext, Authenticated, useToken }
Next, use the AuthContext
to wrap anything that may require
an authenticated user / an access token for an authenticated user.
Typically, you would wrap the whole app inside of an AuthContext
:
1function App() { 2 return ( 3 <AuthContext> 4 // ... all my other components, e.g. router, pages, etc. 5 </AuthContext> 6 ) 7}
Thirdly, when implementing a component that requires an authenticated user,
wrap anything you want to protect from the public in an Authenticated
component. This will ensure the user gets authanticated, before anything
wrapped by Authenticated
gets mounted / rendered:
1function ProtectedComponent() { 2 return ( 3 <Authenticated> 4 <ProtectedComponent /> 5 </Authenticated> 6 ) 7}
Lastly, if you require the access token, you can use the useToken()
hook:
1function ComponentWithToken() { 2 const { access_token } = useToken() 3 const [data, setData] = useState(null) 4 useEffect(() => { 5 if (!data) { 6 fetchData({ token: access_token }).then(setData) 7 } 8 }, [access_token]) 9 return ( 10 // render the data (or a loading indicator, while data === null) 11 ) 12}
Note: You need to provide your own fetchData()
function.
In addition to the required properties (clientId
etc), the following properties can be specified when calling createAuthContext()
:
busyIndicator
: A React element to be rendered while logging in, e.g. <Spinner />
.fetch
: HTTP requests to talk to the OAuth2 provider are done using window.fetch
, unless you specify your own fetch
function as a property.storage
: By default, authentication information (the token) is kept in window.sessionStorage
. If you want to use different storage (e.g. window.localStorage
), set this property. (TODO: won't work yet, as we don't check expiry of tokens!)tokenEndpoint
: The default token endpoint is ${provider}/token
. Configure a different token endpoint here, if your OAuth2 provider does not follow this convention.Check the live demo (see above), also checkout the test app.
You can run the example, after cloning the repo, and:
1npm i 2npm run start
... then connect to http://localhost:3001.
Run the example, see above. As the example runs via react-scripts
, you
can live-edit the sample, and the code of this package,
which lives under ./src/lib
.
It's fully functional, but does not deal with token expiry and/or certain error conditions yet. See the issues and/or add a new issue.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
security policy file not detected
Details
Reason
license file not detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
104 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More