LINE

Get your LINE credentials

  1. Create a channel in the LINE Developers Console.
  2. Note your Channel ID (client_id) and Channel secret (client_secret).
  3. In the channel settings, add your Redirect URI, e.g. http://localhost:3000/api/auth/callback/line for local development.
  4. Enable required scopes (at least openid; add profile, email if 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.

config/auth.rb
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".

server.rb
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.

server.rb
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:

config/auth.rb
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:

server.rb
response = auth.api.sign_in_with_oauth2(
  body: {
    provider_id: "line-jp",
    callback_url: "/dashboard",
    disable_redirect: true
  }
)

redirect_url = response.fetch(:url)

On this page