
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
oauth2-popup-flow
Advanced tools
____ _ _ ___
/ __ \ /\ | | | | |__ \
| | | | / \ _ _| |_| |__ ) |
| | | |/ /\ \| | | | __| '_ \ / /
| |__| / ____ \ |_| | |_| | | |/ /_
\____/_/ \_\__,_|\__|_| |_|____|
/$$$$$$$
| $$__ $$
| $$ \ $$ /$$$$$$ /$$$$$$ /$$ /$$ /$$$$$$
| $$$$$$$//$$__ $$ /$$__ $$| $$ | $$ /$$__ $$
| $$____/| $$ \ $$| $$ \ $$| $$ | $$| $$ \ $$
| $$ | $$ | $$| $$ | $$| $$ | $$| $$ | $$
| $$ | $$$$$$/| $$$$$$$/| $$$$$$/| $$$$$$$/
|__/ \______/ | $$____/ \______/ | $$____/
| $$ | $$
| $$ | $$ ______ _
|__/ |__/ | ____| |
| |__ | | _____ __
| __| | |/ _ \ \ /\ / /
| | | | (_) \ V V /
|_| |_|\___/ \_/\_/
window.open
.oauth2PopupFlow.token()
which returns a Promise<string>
of the token.oauth2PopupFlow.tokenPayload()
which returns a Promise<TokenPayload>
.If the user isn't logged in, the typical OAuth2 implicit grant flow forwards the user to the authorization server's login page (separate from your app) and then redirects them back. The issue with this is that it requires the app to be reloaded in order to grab a token. This reload complicates your application and may result in lost work due to the app reloading.
The popup is a simple solution that allows the user to load the hosted login page and come back to your app while keeping the state of your application.
npm install --save oauth2-popup-flow
import { OAuth2PopupFlow } from 'oauth2-popup-flow';
// create a type for the payload of the token
interface TokenPayload {
exp: number;
other: string;
stuff: string;
username: string;
}
// create an instance of `OAuth2PopupFlow`
export const auth = new OAuth2PopupFlow<TokenPayload>({
authorizationUri: 'https://example.com/oauth/authorize',
clientId: 'YOUR_CLIENT_ID',
redirectUri: 'http://localhost:8080/redirect',
scope: 'openid profile',
});
// opens the login popup
// if the user is already logged in, it won't open the popup
auth.tryLoginPopup().then(result => {
if (result === 'ALREADY_LOGGED_IN') {
// ...
} else if (result === 'POPUP_FAILED') {
// ...
} else if (result === 'SUCCESS') {
// ...
}
});
// synchronously returns whether or not the user is logged in
const loggedIn = auth.loggedIn();
async function someAsyncFunction() {
// open the popup
auth.tryLoginPopup();
// await until authorized
const token = await auth.token();
const response = await fetch('https://example.com', {
method: 'POST',
headers: new Headers({
Authorization: `Bearer ${token}`,
}),
});
}
async function getInfoFromToken() {
// open the popup
auth.tryLoginPopup();
// returns the decoded payload of the token when authorized
const payload = await auth.tokenPayload();
return payload.username;
}
someAsyncFunction();
getInfoFromToken().then(username => console.log({ username }));
// also implements EventTarget so you can add event listeners for `login` and `logout`
auth.addEventListener('login', () => {
console.log('user was logged in');
});
auth.addEventListener('logout', () => {
console.log('user was logged out');
});
Check out the API docs for more info
String.prototype.startsWith
(you may need a polyfill if you're targeting IE etc)FAQs
A very simple oauth2 implicit flow library that uses window.open.
The npm package oauth2-popup-flow receives a total of 563 weekly downloads. As such, oauth2-popup-flow popularity was classified as not popular.
We found that oauth2-popup-flow 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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.