iOS and Android Native wrapper for LINE Mobile SDK.
- React native
0.48.+
. - LineSDK iOS
5.0.0
and Android5.0.1
.
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
Follow all the configuration steps in LINE Login iOS integration guide
- Follow all the configuration steps in LINE Login Android integration guide
- Add the string
line_channel_id
to yourstrings.xml
file onandroid/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>
-
Download the line Android SDK here and save it on a new folder named
libs
under yourapp
folder on your android project or you can go tonode_modules/react-native-line-sdk/android/libs
and copyaar
files to yourlibs
folder onandroid/app/libs
-
Add the following to your app's build.gradle:
repositories {
flatDir {
dirs 'libs'
}
}
- 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
}
First, require the LineLogin
module:
import LineLogin from 'react-native-line-sdk'
Then, you can start using all the functions that are available:
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)
})
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:
profile
: Permission to get the user's profile information.openid
: Used to retrieve an ID tokenemail
: 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
-
currentAccessToken = () => Promise<AccessToken>
: Returns the current access token for the currently logged in user. -
getUserProfile = () => Promise<Profile>
: Returns the profile of the currently logged in user. -
logout = () => Promise<Void>
: Logs out the currently logged in user.
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"
}
To see more of react-native-line-sdk
in action you can check out the source in the example
folder.
react-native-line-sdk
is available under the MIT license. See the LICENCE file for more info.