All Projects → Azard → Egg Oauth2 Server

Azard / Egg Oauth2 Server

Licence: mit
🌟 OAuth2 server plugin for egg.js based on node-oauth2-server

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Egg Oauth2 Server

Egg Cancan
cancancan like authorization plugin for Egg.js
Stars: ✭ 47 (-72.99%)
Mutual labels:  egg, eggjs, egg-plugin
Egg Router Plus
The missing router feature for eggjs
Stars: ✭ 117 (-32.76%)
Mutual labels:  egg, eggjs, egg-plugin
Cool Admin Api
cool-admin-api 是基于egg.js、typeorm、jwt等封装的api开发脚手架、快速开发api接口
Stars: ✭ 188 (+8.05%)
Mutual labels:  egg, eggjs, egg-plugin
egg-sentry
Sentry Plugin For Egg.js
Stars: ✭ 18 (-89.66%)
Mutual labels:  egg, egg-plugin, eggjs
Egg Graphql
Stars: ✭ 345 (+98.28%)
Mutual labels:  egg, eggjs, egg-plugin
egg-parameters
Merge all parameters (ctx.params, ctx.request.query, ctx.request.body) into ctx.params like Rails application.
Stars: ✭ 24 (-86.21%)
Mutual labels:  egg, egg-plugin, eggjs
egg-rbac
Role Based Access Control for eggjs
Stars: ✭ 32 (-81.61%)
Mutual labels:  egg, egg-plugin, eggjs
Egg 24time
A Twitter-like news and social server for Egg. 微信小程序社区全栈解决方案
Stars: ✭ 493 (+183.33%)
Mutual labels:  egg, eggjs, egg-plugin
Egg Authz
egg-authz is an authorization middleware for Egg.js based on Casbin
Stars: ✭ 50 (-71.26%)
Mutual labels:  egg, eggjs, egg-plugin
Cierge
🗝️ Passwordless OIDC authentication done right
Stars: ✭ 1,245 (+615.52%)
Mutual labels:  oauth2, oauth2-server
Ngx Api Utils
ngx-api-utils is a lean library of utilities and helpers to quickly integrate any HTTP API (REST, Ajax, and any other) with Angular.
Stars: ✭ 92 (-47.13%)
Mutual labels:  npm-package, oauth2
Flask Oauthlib
YOU SHOULD USE https://github.com/lepture/authlib
Stars: ✭ 1,429 (+721.26%)
Mutual labels:  oauth2, oauth2-server
Egg Schedule
Schedule plugin for egg
Stars: ✭ 76 (-56.32%)
Mutual labels:  egg, egg-plugin
Node Oauth2 Server Mongo Example
Working oauth2 server with mongodb storage and minimal configuration
Stars: ✭ 76 (-56.32%)
Mutual labels:  oauth2, oauth2-server
Egg Passport
passport plugin for egg
Stars: ✭ 98 (-43.68%)
Mutual labels:  egg, egg-plugin
Egg Sofa Rpc
SOFARPC plugin for egg
Stars: ✭ 71 (-59.2%)
Mutual labels:  eggjs, egg-plugin
Egg Mongo Native
MongoDB egg.js plugin using native driver.
Stars: ✭ 69 (-60.34%)
Mutual labels:  eggjs, egg-plugin
Django Oauth2 Server
OAuth2 server written in Python with Django
Stars: ✭ 108 (-37.93%)
Mutual labels:  oauth2, oauth2-server
Blog
天猪部落阁 http://atian25.github.io
Stars: ✭ 1,527 (+777.59%)
Mutual labels:  egg, eggjs
Node Oauth2 Server Example
Working oauth2 server with minimal configuration
Stars: ✭ 115 (-33.91%)
Mutual labels:  oauth2, oauth2-server

egg-oauth2-server

NPM version build status Test coverage David deps Known Vulnerabilities npm download

Chinese Example | 中文样例教程(注意:文章里使用的是该插件 v1.x 版本,部分 API 名称有变化,主要流程一致)

egg-oauth2-server is a module that easily adds oauth2 capability to egg-based servers.

  • egg 2.x use egg-oauth2-server latest (Node >= 8.0.0)
  • egg 1.x use egg-oauth2-server 2.0.x (Node >= 6.0.0)

Install

$ npm i egg-oauth2-server --save

Usage

// {app_root}/config/plugin.js
exports.oAuth2Server = {
  enable: true,
  package: 'egg-oauth2-server',
};

// {app_root}/app/router.js
app.all('/user/token', app.oAuth2Server.token());
app.get('/user/authorize', app.oAuth2Server.authorize(), 'user.code');
app.get('/user/authenticate', app.oAuth2Server.authenticate(), 'user.authenticate');

// `ctx.state.oauth` has token or code data after middleware for controller.
// {app_root}/config/config.default.js
module.exports = config => {
  const exports = {};
  exports.oAuth2Server = {
    debug: config.env === 'local',
    grants: [ 'password' ],
  };
  return exports;
};

See test/fixtures/apps/oauth2-server-test/config/config.unittest.js for reference.

// {app_root}/app/extend/oauth.js
// or {app_root}/app/extend/oauth.ts
'use strict';

// need implement some follow functions
module.exports = app => {  
  class Model {
    constructor(ctx) {}
    async getClient(clientId, clientSecret) {}
    async getUser(username, password) {}
    async saveAuthorizationCode(code, client, user) {}
    async getAuthorizationCode(authorizationCode) {}
    async revokeAuthorizationCode(code) {}
    async saveToken(token, client, user) {}
    async getAccessToken(bearerToken) {}
    async revokeToken(token) {}
  }  
  return Model;
};

For full description, check out https://www.npmjs.com/package/oauth2-server.

Examples

A simple password-mode OAuth 2.0 server. Full code at test/fixtures/apps/oauth2-server-test/app/extend/oauth.js

password mode app.oauth.token() lifecycle

getClient --> getUser --> saveToken

password mode app.oauth.authenticate() lifecycle

Only getAccessToken

authorization_code mode app.oauth.authorize() lifecycle

getClient --> getUser --> saveAuthorizationCode

authorization_code mode app.oauth.token() lifecycle

getClient --> getAuthorizationCode --> revokeAuthorizationCode --> saveToken

authorization_code mode app.oauth.authenticate() lifecycle

Only getAccessToken

Questions & Suggestions

Please open an issue. PRs are welcomed too.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].