Class: StandardId::Providers::Base
- Inherits:
-
Object
- Object
- StandardId::Providers::Base
- Defined in:
- lib/standard_id/providers/base.rb
Overview
Base class for social login providers.
All provider implementations (Google, Apple, GitHub, etc.) must inherit from this class and implement the required interface methods. This enables a plugin architecture where provider gems can be developed independently and registered with StandardId.
Class Method Summary collapse
-
.authorization_url(state:, redirect_uri:, **options) ⇒ String
Generate OAuth authorization URL for redirecting users to the provider.
-
.callback_path ⇒ String
Returns the callback path for this provider.
-
.config_schema ⇒ Hash
Define configuration schema fields for this provider.
-
.default_scope ⇒ String?
Returns the default OAuth scope for this provider.
-
.get_user_info(code: nil, id_token: nil, access_token: nil, redirect_uri: nil, **options) ⇒ HashWithIndifferentAccess
Exchange OAuth credentials for user information.
-
.provider_name ⇒ String
Provider identifier used for routing and configuration.
-
.resolve_params(params, context: {}) ⇒ Hash
Resolve provider-specific parameters based on context.
-
.setup ⇒ void
Optional setup hook called when provider is registered.
-
.skip_csrf? ⇒ Boolean
Whether to skip CSRF verification for web callbacks.
-
.supported_authorization_params ⇒ Array<Symbol>
Returns list of supported authorization parameters for this provider.
-
.supports_mobile_callback? ⇒ Boolean
Whether this provider supports mobile callback flow.
Class Method Details
.authorization_url(state:, redirect_uri:, **options) ⇒ String
Generate OAuth authorization URL for redirecting users to the provider.
67 68 69 |
# File 'lib/standard_id/providers/base.rb', line 67 def (state:, redirect_uri:, **) raise NotImplementedError, "#{name} must implement .authorization_url" end |
.callback_path ⇒ String
Returns the callback path for this provider.
Used to build the OAuth redirect URI. Uses the engine’s route helpers to respect the mount path.
164 165 166 |
# File 'lib/standard_id/providers/base.rb', line 164 def callback_path StandardId::WebEngine.routes.url_helpers.auth_callback_provider_path(provider: provider_name) end |
.config_schema ⇒ Hash
Define configuration schema fields for this provider.
Returns a hash of field definitions compatible with StandardConfig schema DSL. These fields will be registered under the :social configuration scope.
122 123 124 |
# File 'lib/standard_id/providers/base.rb', line 122 def config_schema {} end |
.default_scope ⇒ String?
Returns the default OAuth scope for this provider.
Can be overridden by passing :scope in authorization_url options. Returns nil by default, letting the provider use its own default.
178 179 180 |
# File 'lib/standard_id/providers/base.rb', line 178 def default_scope nil end |
.get_user_info(code: nil, id_token: nil, access_token: nil, redirect_uri: nil, **options) ⇒ HashWithIndifferentAccess
Exchange OAuth credentials for user information.
Providers must support at least one of: authorization code, ID token, or access token. The method should validate the credentials with the provider and return standardized user information.
103 104 105 |
# File 'lib/standard_id/providers/base.rb', line 103 def get_user_info(code: nil, id_token: nil, access_token: nil, redirect_uri: nil, **) raise NotImplementedError, "#{name} must implement .get_user_info" end |
.provider_name ⇒ String
Provider identifier used for routing and configuration.
48 49 50 |
# File 'lib/standard_id/providers/base.rb', line 48 def provider_name raise NotImplementedError, "#{name} must implement .provider_name" end |
.resolve_params(params, context: {}) ⇒ Hash
Resolve provider-specific parameters based on context.
Override this method to customize parameters based on flow type, platform, or other contextual information. This allows providers to handle platform-specific requirements (e.g., Apple’s different client IDs for web vs mobile).
147 148 149 |
# File 'lib/standard_id/providers/base.rb', line 147 def resolve_params(params, context: {}) params end |
.setup ⇒ void
This method returns an undefined value.
Optional setup hook called when provider is registered.
Override this method to perform initialization tasks like:
-
Registering additional routes
-
Adding custom validations
-
Setting up caching for JWKS
237 238 239 |
# File 'lib/standard_id/providers/base.rb', line 237 def setup # Override in subclasses if needed end |
.skip_csrf? ⇒ Boolean
Whether to skip CSRF verification for web callbacks.
Some providers (like Apple) use POST callbacks which require CSRF verification to be skipped. Override this method to return true if your provider uses POST callbacks.
195 196 197 |
# File 'lib/standard_id/providers/base.rb', line 195 def skip_csrf? false end |
.supported_authorization_params ⇒ Array<Symbol>
Returns list of supported authorization parameters for this provider.
Include :nonce in this list for OIDC providers to enable nonce validation. Nonce provides replay attack protection for ID tokens.
224 225 226 |
# File 'lib/standard_id/providers/base.rb', line 224 def [] end |
.supports_mobile_callback? ⇒ Boolean
Whether this provider supports mobile callback flow.
Mobile callbacks are used when native apps (especially Android) need a server-side redirect back to the app after OAuth. For example, Apple Sign In on Android uses a web-based flow that requires the server to redirect back to the app.
208 209 210 |
# File 'lib/standard_id/providers/base.rb', line 208 def supports_mobile_callback? false end |