react-native-line-auth
v0.1.0
Published
Standalone React Native bridge for LINE Login using the official LINE iOS and Android SDKs.
Maintainers
Readme
react-native-line-auth
Standalone LINE Login for React Native using the official native LINE SDKs directly.
- No dependency on another React Native LINE Login npm package
- Android: official
com.linecorp.linesdk:linesdk - iOS: official
LineSDKSwift - Typed TypeScript API
- React Native autolinking
Requirements
- React Native 0.76 or newer
- Android API 24 or newer
- iOS 13.0 or newer
- A LINE Login channel
Install
Install this package only:
npm install react-native-line-authFor iOS, install pods:
cd ios
pod install
cd ..The package automatically adds the official native LINE SDK through Gradle on Android and CocoaPods on iOS. You do not install another LINE Login npm package.
LINE Developers Console
Create or open a LINE Login channel and configure both platforms.
Android
Register:
- Your Android application ID, for example
com.example.myapp - Your production and debug package signatures as needed
The package requires minSdkVersion 24 or later. If your project uses a lower value, update it in the application Android configuration.
iOS
Register:
- Your iOS bundle identifier
- Universal Link settings when your application uses them
Add the following values to the application Info.plist:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>line3rdp.$(PRODUCT_BUNDLE_IDENTIFIER)</string>
</array>
</dict>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>lineauth2</string>
</array>iOS AppDelegate setup
The LINE SDK must be initialized when the iOS application launches so that cold-start login callbacks can be processed.
In AppDelegate.swift, import LINE SDK and React linking:
import LineSDK
import ReactAdd LINE setup inside your existing application(_:didFinishLaunchingWithOptions:) implementation:
LoginManager.shared.setup(
channelID: "YOUR_LINE_LOGIN_CHANNEL_ID",
universalLinkURL: nil
)Forward URL callbacks to the LINE SDK before the React Native linker:
override func application(
_ app: UIApplication,
open url: URL,
options: [UIApplication.OpenURLOptionsKey: Any] = [:]
) -> Bool {
if LoginManager.shared.application(
app,
open: url,
options: options
) {
return true
}
return RCTLinkingManager.application(
app,
open: url,
options: options
)
}Keep your application’s existing AppDelegate logic and merge these lines into it rather than replacing the entire file.
Basic usage
Configure once near application startup:
import { configureLineLogin } from 'react-native-line-auth';
await configureLineLogin({
channelId: 'YOUR_LINE_LOGIN_CHANNEL_ID',
});Sign in:
import {
Scope,
isLineLoginCancelled,
signInWithLine,
} from 'react-native-line-auth';
try {
const result = await signInWithLine({
scopes: [Scope.Profile, Scope.OpenId],
});
console.log(result.user);
console.log(result.accessToken);
console.log(result.idToken);
} catch (error) {
if (!isLineLoginCancelled(error)) {
console.error(error);
}
}Sign out:
import { signOutFromLine } from 'react-native-line-auth';
await signOutFromLine();Send login to your backend
The npm package does not know your backend URL. Keep backend calls inside your application:
const line = await signInWithLine();
const response = await fetch('https://api.example.com/auth/line', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
accessToken: line.accessToken,
idToken: line.idToken,
}),
});Your backend must verify the token with LINE before trusting the user identity or creating an application session. Do not trust userId, displayName, or other profile values sent by the client without server-side verification.
Login options
import { BotPrompt, Scope, signInWithLine } from 'react-native-line-auth';
const result = await signInWithLine({
scopes: [Scope.Profile, Scope.OpenId, Scope.Email],
nonce: 'cryptographically-random-nonce',
botPrompt: BotPrompt.Normal,
onlyWebLogin: false,
});Scope.Email requires email permission to be enabled for the LINE Login channel.
API
Authentication
configureLineLogin(options): Promise<void>
signInWithLine(options?): Promise<LineAuthResult>
signOutFromLine(): Promise<void>
isLineLoginConfigured(): booleanTokens and profile
getCurrentLineAccessToken(): Promise<LineAccessToken>
refreshLineAccessToken(): Promise<LineAccessToken>
verifyLineAccessToken(): Promise<LineTokenVerification>
getLineProfile(): Promise<LineAuthUser>
getLineFriendshipStatus(): Promise<LineFriendshipStatus>Error handling
import {
LINE_LOGIN_CANCELLED,
LineAuthError,
isLineLoginCancelled,
} from 'react-native-line-auth';Native cancellation codes from iOS and Android are normalized to LOGIN_CANCELLED.
Returned login result
interface LineAuthResult {
accessToken: string;
expiresIn: number;
issuedAt: number | null;
expiresAt: number | null;
idToken: string | null;
idTokenNonce: string | null;
grantedScopes: string[];
user: {
userId: string;
displayName: string;
pictureUrl: string | null;
statusMessage: string | null;
} | null;
friendshipStatusChanged: boolean | null;
}Token timestamps are Unix seconds.
Native dependencies
This npm package has no third-party LINE npm dependency. Native dependency resolution is handled by each platform:
React Native application
↓
react-native-line-auth
↓
Official LINE SDK
├─ Android Maven: com.linecorp.linesdk:linesdk:5.12.0
└─ iOS CocoaPods: LineSDKSwift 5.16.xTroubleshooting
Native module is not linked
Rebuild the application after installation. For iOS, run pod install first.
Android login returns AUTHENTICATION_AGENT_ERROR
Check the Android package name and package signature registered in the LINE Developers Console.
iOS opens LINE but does not return to the app
Check the URL scheme in Info.plist and confirm that AppDelegate forwards the URL to LoginManager.shared.application(...).
Login works after reopening the app but not from a cold start
Initialize LoginManager.shared in AppDelegate during application launch, not only from JavaScript.
Development
npm ci
npm run check
npm pack --dry-runLicense
MIT
