Skip to content

toeyanuntachai/react-native-line

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

React native LINE

iOS and Android Native wrapper for LINE Mobile SDK.

Requirements

  • React native 0.48.+.
  • LineSDK iOS 5.0.0 and Android 5.0.1.

Installation

First, install the npm package and link it to your Android and iOS projects with react-native link.

  npm install react-native-line-sdk
  react-native link react-native-line-sdk

iOS Setup

Follow all the configuration steps in LINE Login iOS integration guide

Android Setup

  1. Follow all the configuration steps in LINE Login Android integration guide
  2. Add the string line_channel_id to your strings.xml file on android/app/src/main/res/values folder with the the channel id that you have on your line console.
<string name="line_channel_id" translatable="false">Your channel id here</string>
  1. Download the line Android SDK here and save it on a new folder named libs under your app folder on your android project or you can go to node_modules/react-native-line-sdk/android/libs and copy aar files to your libs folder on android/app/libs

  2. Add the following to your app's build.gradle:

repositories {
    flatDir {
        dirs 'libs'
    }
}
  1. Add the following dependencies to your app's build.gradle:
implementation('com.madgag.spongycastle:prov:1.58.0.0') {
  exclude group: 'junit', module: 'junit'
}
api 'io.jsonwebtoken:jjwt-api:0.10.5'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.10.5'
runtimeOnly ('io.jsonwebtoken:jjwt-orgjson:0.10.5') {
  exclude group: 'org.json', module: 'json' //provided by Android natively
}

Usage

First, require the LineLogin module:

import LineLogin from 'react-native-line-sdk'

Then, you can start using all the functions that are available:

login

login = () => Promise<{Profile, AccessToken}>

Starts the login flow of LINE SDK, if user has installed LINE app, it will open it otherwise it will open browser or in-app browser)

Example:

  LineLogin.login()
    .then((user) => {
      console.log(user.profile.displayName)
    })
    .catch((err) => {
      console.log(err)
    })

loginWithPermission

loginWithPermissions = (permissions) => Promise<{Profile, AccessToken, Email}>

The login flow same with login() but you need to pass the permission (or scope). There are three scope you can send:

  1. profile: Permission to get the user's profile information.
  2. openid: Used to retrieve an ID token
  3. email: Permission to get the user's email address. openid must be specified at the same time.

More info: LINE Login integration web-app (see Scope section)

Example:

  LineLogin.loginWithPermissions(['profile', 'openid', 'email'])
    .then(user => {
      console.log('accessToken',user.accessToken.accessToken);
      console.log('email',user.email);
      console.log('profile',user.profile);
    })
    .catch(err => {
      console.log(err);
    });
};

Starts the login

  1. currentAccessToken = () => Promise<AccessToken>: Returns the current access token for the currently logged in user.

  2. getUserProfile = () => Promise<Profile>: Returns the profile of the currently logged in user.

  3. logout = () => Promise<Void>: Logs out the currently logged in user.

Return values

The following objects are returned on the methods described above:

{
  "accessToken": {
    "expirationDate": "2592000000",
    "accessToken": "some token"
  },
  "profile": {
    "pictureURL": "profile picture url",
    "statusMessage": "user status messaage",
    "userID": "user id",
    "displayName": "user displayed name"
  },
  "email": "user email"
}

Example

To see more of react-native-line-sdk in action you can check out the source in the example folder.

Authors

License

react-native-line-sdk is available under the MIT license. See the LICENCE file for more info.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 44.3%
  • Objective-C 28.9%
  • JavaScript 19.6%
  • Python 6.8%
  • Ruby 0.4%