0.2.9 • Published 4 years ago

passport-line-auth v0.2.9

Weekly downloads
349
License
MIT
Repository
github
Last release
4 years ago

passport-line-auth

Build Status codecov Greenkeeper badge

NPM

Package Quality

Passport strategy for authenticating with LINE using the OAuth 2.0 API and OpenID Connect.

How to Install

npm

npm install passport-line-auth --save

Yarn

yarn add passport-line-auth

Usage

Create an Service

Before using passport-line-auth, you must register an Services with LINE. If you have not already done so, a new services can be created at LINE Developers. Your service will be issued an channel ID and channel secret, which need to be provided to the strategy. You will also need to configure a redirect URI which matches the route in your service.

Configure Strategy

The LINE authentication strategy authenticates users using a LINE account and OAuth 2.0 tokens. The channel ID and secret obtained when creating an service are supplied as options when creating the strategy. The strategy also requires a verify callback, which receives the access token and optional refresh token, as well as profile which contains the authenticated user's LINE profile. The verify callback must call cb providing a user to complete authentication.

passport.use(new LineStrategy({
    channelID: LINE_CHANNEL_ID,
    channelSecret: LINE_CHANNEL_SECRET,
    callbackURL: "http://localhost:3000/auth/line/callback",
    scope: ['profile', 'openid'],
    botPrompt: 'normal',
    uiLocales: 'en-US',
  },
  function(accessToken, refreshToken, profile, cb) {
    User.findOrCreate({ lineId: profile.id }, function (err, user) {
      return cb(err, user);
    });
  }
));
passport.use(new LineStrategy({
    channelID: LINE_CHANNEL_ID,
    channelSecret: LINE_CHANNEL_SECRET,
    callbackURL: "http://localhost:3000/auth/line/callback",
    scope: ['profile', 'openid', 'email'],
    botPrompt: 'normal',
    uiLocales: 'en-US',
  },
  function(accessToken, refreshToken, params, profile, cb) {
    var email = jwt.decode(params.id_token)
    User.findOrCreate({ lineId: profile.id }, function (err, user) {
      return cb(err, user);
    });
  }
));

Options

ParameterTypeRequiredDefaultDescription
channelIDStringRequiredChannel's Id by LINE
channelSecretStringRequiredChannel's secret by LINE
callbackURLStringRequiredURL that users are redirected to after authentication and authorization. Must match one of the the callback URLs registered for your channel in the console.
scopeArrayRequired['profile', 'openid']Permissions granted by the user. Set value to either profile, openid or email. If
botPromptStringOptionalnullDisplays an option to add a bot as a friend during login. Set value to either normal or aggressive. For more information, see Linking a bot with your LINE Login channel.
uiLocalesStringOptionalnullDisplay language for LINE Login screens. For more information, see Linking a bot with your LINE Login channel.

Response

NameTypeDescription
accessTokenStringAccess token. Valid for 30 days.
refreshTokenStringToken used to get a new access token. Valid up until 10 days after the access token expires.
idTokenStringJWT that includes information about the user. This field is returned only if openid is specified in the scope. For more information, see ID tokens.

Exmaple

First time, you need set channel id, secret and redirect uri at Exmaple, then install packages and npm start.

Reference

License

The MIT License

Copyright(c)2019 Ivan Wei (Wei, Hong-Lin) [https://blog.ivanwei.co/](https://blog.ivanwei.co/)

0.2.9

4 years ago

0.2.8

5 years ago

0.2.7

5 years ago

0.2.6

5 years ago

0.2.5

5 years ago

0.2.4

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago