@appwise/oauth2-server
TypeScript icon, indicating that this package has built-in type declarations

0.1.6 • Public • Published

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

/@appwise/oauth2-server/

    Package Sidebar

    Install

    npm i @appwise/oauth2-server

    Weekly Downloads

    329

    Version

    0.1.6

    License

    ISC

    Unpacked Size

    91.7 kB

    Total Files

    52

    Last publish

    Collaborators

    • maartensijmkens
    • jeffreynijs
    • kobe-kwanten-wisemen
    • wouter.appwise
    • jorenvandeweyer