@lighthouseapps/egg-oauth2
v1.0.4
Published
> Javascript oauth2 server
Downloads
11
Keywords
Readme
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