Generic OAuth

Configure custom OAuth 2.0 providers.

This page documents the current Ruby port behavior. Ruby uses snake_case option names and auth.api method names; HTTP paths and JSON keys keep the upstream wire shape where implemented.

Configure

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: [{ provider_id: "example", client_id: ENV.fetch("OAUTH_CLIENT_ID"), client_secret: ENV.fetch("OAUTH_CLIENT_SECRET") }])
  ]
)

Usage

server.rb
response = auth.api.sign_in_with_oauth2(body: { providerId: "example", callbackURL: "/dashboard" })
link = auth.api.o_auth2_link_account(headers: { "cookie" => request.env["HTTP_COOKIE"] }, body: { providerId: "example" })

Routes

MethodPathRuby API method
POST/sign-in/oauth2auth.api.sign_in_with_oauth2
GET/callback/oauth2/:providerIdauth.api.o_auth2_callback
POST/oauth2/linkauth.api.o_auth2_link_account

Options

Current Ruby options accepted by BetterAuth::Plugins.generic_oauth:

  • config

Support Notes

  • The examples above are based on Ruby plugin source and tests in packages/better_auth.
  • If an upstream section is not represented here, treat it as not yet documented or not yet supported by the Ruby port until the matching Ruby implementation exists.

On this page