LINE
Get your LINE credentials
- Create a channel in the LINE Developers Console.
- Note your Channel ID (client_id) and Channel secret (client_secret).
- In the channel settings, add your Redirect URI, e.g.
http://localhost:3000/api/auth/callback/linefor local development. - Enable required scopes (at least
openid; addprofile,emailif you need name, avatar, email).
See the LINE Login v2.1 reference for details.
Configure the provider
Add your LINE credentials to BetterAuth::SocialProviders.line in your auth configuration.
require "better_auth"
auth = BetterAuth.auth(
secret: ENV.fetch("BETTER_AUTH_SECRET"),
base_url: ENV.fetch("BETTER_AUTH_URL", "http://localhost:3000"),
social_providers: {
line: BetterAuth::SocialProviders.line(
client_id: ENV.fetch("LINE_CLIENT_ID"),
client_secret: ENV.fetch("LINE_CLIENT_SECRET")
)
}
)Usage
Sign In with LINE
Use the client auth.api.sign_in_social with provider: "line".
response = auth.api.sign_in_social(
body: {
provider: "line",
callback_url: "/dashboard",
error_callback_url: "/login",
disable_redirect: true
}
)
redirect_url = response.fetch(:url)Sign In with LINE using ID Token (optional)
If you obtain the LINE ID token on the client, you can sign in directly without redirection.
result = auth.api.sign_in_social(
body: {
provider: "line",
id_token: {
token: line_id_token,
access_token: line_access_token
}
}
)
user = result.fetch(:user)Notes
- Default scopes include
openid profile email. Adjust as needed via provider options. - Verify redirect URI exactly matches the value configured in LINE Developers Console.
- LINE ID token verification uses the official endpoint and checks audience and optional nonce per spec.
Designing a login button? Follow LINE's button guidelines.
Multi-Channel Support
LINE requires separate OAuth channels for different countries (Japan, Thailand, Taiwan, etc.), each with its own client_id and client_secret. The standard BetterAuth::SocialProviders.line configuration only supports a single channel.
To support multiple countries/channels, use the Generic OAuth plugin with the line() helper function. This allows you to configure multiple LINE providers with different provider_ids:
require "better_auth"
auth = BetterAuth.auth(
secret: ENV.fetch("BETTER_AUTH_SECRET"),
base_url: ENV.fetch("BETTER_AUTH_URL", "http://localhost:3000"),
plugins: [
BetterAuth::Plugins.generic_oauth(
config: [
BetterAuth::Plugins.line(
provider_id: "line-jp",
client_id: ENV.fetch("LINE_JP_CLIENT_ID"),
client_secret: ENV.fetch("LINE_JP_CLIENT_SECRET")
),
BetterAuth::Plugins.line(
provider_id: "line-th",
client_id: ENV.fetch("LINE_TH_CLIENT_ID"),
client_secret: ENV.fetch("LINE_TH_CLIENT_SECRET")
),
BetterAuth::Plugins.line(
provider_id: "line-tw",
client_id: ENV.fetch("LINE_TW_CLIENT_ID"),
client_secret: ENV.fetch("LINE_TW_CLIENT_SECRET")
)
]
)
]
)When signing in, use the appropriate provider_id (e.g., "line-jp", "line-th", "line-tw") to identify which channel to use:
response = auth.api.sign_in_with_oauth2(
body: {
provider_id: "line-jp",
callback_url: "/dashboard",
disable_redirect: true
}
)
redirect_url = response.fetch(:url)