@appwise/oauth2-server
v0.1.7
Published
A package for an oauth2 server
Downloads
1,452
Keywords
Readme
express-oauth2
Installation
npm install express-oauth2
Adding a authentication method to your project
In order to add a new authentication method to your project, first add the new integration:
export const oauth: OAuth2Server = createOAuth2({
scopes: Object.values(Scope),
services: {
userService,
clientService,
tokenService
},
integrations: {
google: true
}
})
Add the integration to the client grants in the client service:
client.grants = ['password', 'refresh_token', 'google']
Implement the integration user service method:
createOrGetGoogleUser?: (payload: IGoogleResponse) => Promise<User>
async createOrGetGoogleUser (payload: IGoogleResponse): Promise<User> {
const user = await User.findOne({ where: { email: payload.email } })
if (user != null) return user
const newUser = User.create({
email: payload.email,
password: this.getRandomPassword()
})
await this.hashPassword(newUser, newUser.password)
return await newUser.save()
}