Egg Oauth2 Server

🌟 OAuth2 server plugin for egg.js based on node-oauth2-server
Alternatives To Egg Oauth2 Server
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Egg Oauth2 Server1591034 years ago21June 12, 20193mitJavaScript
:star2: OAuth2 server plugin for egg.js based on node-oauth2-server
Firewalld Ui115
9 months ago4JavaScript
Node.js 的 Firewalld 界面化,基于 Node.js 适用于 个人服务器 和 NAS 的 Firewalld(防火墙) 界面化,不需要记忆操作命令,更没有 Firewalld 的区域概念,和 iptables 复杂的 表链结构 .界面上点击创建一些规则就可以达到 自动 屏蔽和放行 IP 的目的.
Egg Blog84
5 years ago1mitJavaScript
blog api base on eggjs.
Tomato Work Server45
a year ago1mitJavaScript
🍅 Tomato Work Server for Egg.js
Node Server19
2 years ago25JavaScript
(@NestJS refactoring)⚡️My personal website's api server, a RESTful application that powered by @eggjs
Generator Deepexi Eggjs1424 years ago20September 27, 20193JavaScript
deepexi eggjs scaffold generator
Egg Opentracing Zipkin7355 years ago1June 29, 2018mitJavaScript
Report trace infomation to zipkin server in Egg.js.
Jmgs_server6
5 years agoJavaScript
jmgs server written by eggjs #https://github.com/g1mi/jmgs_server
Webpack Vue5
5 years agoJavaScript
Integrated webpack 3 and vue and eggjs server for development and production.
Hoopics Admin Restful Api Server5
3 years agoRust
hoopics website admin restful api server
Alternatives To Egg Oauth2 Server
Select To Compare


Alternative Project Comparisons
Readme

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

Popular Eggjs Projects
Popular Server Projects
Popular Frameworks Categories
Related Searches

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Javascript
Node
Server
Oauth2
Oauth
Authorization
Egg
Eggjs
Oauth2 Server
Egg Plugin