Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

grant-koa

Package Overview
Dependencies
Maintainers
1
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grant-koa

Grant OAuth Proxy middleware for Koa

  • 5.4.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is grant-koa?

The grant-koa npm package is a middleware for Koa that simplifies OAuth integration. It allows developers to easily set up OAuth providers and handle authentication flows in their Koa applications.

What are grant-koa's main functionalities?

OAuth Provider Configuration

This code sample demonstrates how to configure the grant-koa middleware with a Google OAuth provider. It sets up the necessary session management and initializes Grant with the required OAuth provider settings.

const Koa = require('koa');
const session = require('koa-session');
const Grant = require('grant-koa');

const app = new Koa();
app.keys = ['some secret hurr'];
app.use(session(app));

const grant = new Grant({
  defaults: {
    protocol: 'http',
    host: 'localhost:3000',
    transport: 'session',
    state: true
  },
  google: {
    key: 'YOUR_GOOGLE_CLIENT_ID',
    secret: 'YOUR_GOOGLE_CLIENT_SECRET',
    scope: ['profile', 'email'],
    callback: '/handle_google_callback'
  }
});

app.use(grant);

app.listen(3000);

Handling OAuth Callbacks

This code sample shows how to handle the OAuth callback in a Koa application. After the user is authenticated by Google, the access token is retrieved from the session and can be used to fetch user data.

app.use(async (ctx, next) => {
  if (ctx.path === '/handle_google_callback') {
    const { access_token } = ctx.session.grant.response;
    // Use the access token to fetch user data from Google
    ctx.body = `Access Token: ${access_token}`;
  } else {
    await next();
  }
});

Other packages similar to grant-koa

Keywords

FAQs

Package last updated on 19 Nov 2020

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc