Skip to content

JonasVannieuwenhuijsen/oauth2-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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()
  }

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •