
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
react-oauth-login
Advanced tools
A lightweight React library for OAuth 2.0 authentication and token management
react-oauth-loginは、ReactでOAuth 2.0の認証を簡単に実装するためのライブラリです。useOAuthフックとOAuthコンポーネントを提供し、アクセストークンの取得や検証をシンプルに行うことができます。
useOAuth) とコンポーネント (OAuth) のサポートnpm install react-oauth-login
useOAuthuseOAuthは、OAuth 2.0認証を処理するためのカスタムフックです。
endpoint: 認証エンドポイントURL(例: GoogleのOAuthエンドポイント)params: 認証時に必要なクエリパラメータtoken: アクセストークンverifyToken: トークンの有効期限を確認する関数import { useOAuth } from 'react-oauth-login'
const App = () => {
const { token, verifyToken } = useOAuth({
endpoint: 'https://accounts.google.com/o/oauth2/v2/auth',
params: {
client_id: 'YOUR_CLIENT_ID',
redirect_uri: 'YOUR_REDIRECT_URI',
response_type: 'token',
scope: 'YOUR_REQUESTED_SCOPE',
},
})
if (!verifyToken()) {
return <p>Authenticating...</p>
}
return <p>Authenticated! Token: {token}</p>
}
OAuthOAuthコンポーネントは、useOAuthをラップして、Reactのコンポーネント構造で使いやすくしたものです。
endpoint: 認証エンドポイントURLparams: 認証時に必要なクエリパラメータchildren: トークン情報と検証関数を受け取る子コンポーネントimport { OAuth } from 'react-oauth-login'
const App = () => {
return (
<OAuth
endpoint="https://accounts.google.com/o/oauth2/v2/auth"
params={{
client_id: 'YOUR_CLIENT_ID',
redirect_uri: 'YOUR_REDIRECT_URI',
response_type: 'token',
scope: 'YOUR_REQUESTED_SCOPE',
}}
>
{({ token, verifyToken }) => (
verifyToken() ? <p>Token: {token}</p> : <p>Authenticating...</p>
)}
</OAuth>
)
}
以下は、取得したアクセストークンを使用してFirebase Cloud MessagingのAPIを呼び出す例です。
import { OAuth } from 'react-oauth-login'
export const App = () => {
const sendHandler = async (e, token) => {
e.preventDefault()
const form = new FormData(e.target)
try {
const res = await fetch('https://fcm.googleapis.com/v1/projects/YOUR_PROJECT_ID/messages:send', {
method: 'POST',
headers: {
Authorization: `Bearer ${token}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
message: {
token: form.get('destination'),
notification: {
title: form.get('title'),
body: form.get('body'),
},
},
}),
})
const data = await res.json()
console.log(data)
} catch (err) {
console.error(err)
}
}
return (
<OAuth
endpoint="https://accounts.google.com/o/oauth2/v2/auth"
params={{
client_id: 'YOUR_CLIENT_ID',
redirect_uri: 'YOUR_REDIRECT_URI',
response_type: 'token',
scope: 'https://www.googleapis.com/auth/firebase.messaging',
}}
>
{({ token }) => (
<form onSubmit={(e) => sendHandler(e, token)}>
<label>User Device Token:
<input name="destination" required />
</label>
<label>Title:
<input name="title" required />
</label>
<label>Body:
<input name="body" required />
</label>
<button type="submit">Send Notification</button>
</form>
)}
</OAuth>
)
}
MIT License
FAQs
A lightweight React library for OAuth 2.0 authentication and token management
The npm package react-oauth-login receives a total of 7 weekly downloads. As such, react-oauth-login popularity was classified as not popular.
We found that react-oauth-login demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.