@lighthouseapps/egg-oauth2

1.0.4 • Public • Published

oauth2-server

Javascript oauth2 server

Usage

  const {
    EggOAuth2
  } = require('oauth2-server');

  class OAuth2Model {
    constructor(ctx) {
      this.ctx = ctx;
    }

    getClient(id: String, secret: String): Client {}

    getUser(email: String, password: String): User {}

    getAuthorizationCode(code: String): AuthorizationCode {}

    getAccessToken(token: String): AccessToken {}

    getRefreshToken(token: String): RefreshToken {}

    saveAuthorizationCode(code: AuthorizationCode, client: Client, user: User): AuthorizationCode {}

    saveToken(token: Token, client: Client, user: User): Token {}

    revokeAuthorizationCode(code: AuthorizationCode): Boolean {}

    revokeToken(token: Token): Boolean {}
  }

  const oauth2 = new EggOAuth2(OAuth2Model, {
    grants: [
      'password',
      'authorization_code'
    ]
  });

  /*** MODELS ***/
  // Client = { id, secret, grants, ... }
  // User = { id, email, name, ... }
  // AuthorizationCode = { code , expires_at, user: User, client: Client }
  // AccessToken = { access_token, access_token_expires_at, scope, user: User, client: Client }
  // RefreshToken = { refresh_token, refresh_token_expires_at, scope, user: User, client: Client }
  // Token = { ...AccessToken, ...RefreshToken }

  /*** MIDDLEWARES ***/
  // oauth2.token - access_token/refresh_token
  // oauth2.authenticate - check bearer token
  // oauth2.authorize - authorization_code

Readme

Keywords

none

Package Sidebar

Install

npm i @lighthouseapps/egg-oauth2

Weekly Downloads

0

Version

1.0.4

License

MIT

Unpacked Size

6.36 kB

Total Files

9

Last publish

Collaborators

  • leosampc
  • marlonconstante
  • gustavo-kuze
  • donnes
  • alvarosilveiraa
  • lhdev