Class: Strava::OAuth::Client
- Inherits:
-
Web::Client
- Object
- Web::Client
- Strava::OAuth::Client
- Defined in:
- lib/strava/oauth/client.rb
Overview
OAuth client for Strava authentication.
This client handles the OAuth 2.0 authentication flow with Strava, including:
- Generating authorization URLs
- Exchanging authorization codes for access tokens
- Refreshing expired access tokens
Class Method Summary collapse
-
.config ⇒ Module
Returns the current OAuth client configuration.
-
.configure {|Config| ... } ⇒ Module
Configure the OAuth client with a block.
Instance Method Summary collapse
-
#authorize_url(options = {}) ⇒ String
Generate the authorization URL for OAuth flow.
-
#initialize(options = {}) ⇒ Client
constructor
Initialize a new OAuth client.
-
#oauth_token(options = {}) ⇒ Strava::Models::Token
Exchange authorization code for access token or refresh an expired token.
Constructor Details
Class Method Details
.config ⇒ Module
Returns the current OAuth client configuration.
154 155 156 |
# File 'lib/strava/oauth/client.rb', line 154 def config Config end |
Instance Method Details
#authorize_url(options = {}) ⇒ String
Generate the authorization URL for OAuth flow.
Creates a URL to redirect users to for Strava authorization. After the user authorizes your application, they will be redirected back to your redirect_uri with an authorization code.
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/strava/oauth/client.rb', line 82 def ( = {}) query = .merge( client_id: client_id || raise(ArgumentError, 'Missing Strava client id.'), response_type: [:response_type] || 'code', redirect_uri: [:redirect_uri] || 'http://localhost', approval_prompt: [:approval_prompt] || 'auto', scope: [:scope] || 'read' ) [endpoint, "authorize?#{query.to_query}"].join('/') end |
#oauth_token(options = {}) ⇒ Strava::Models::Token
Exchange authorization code for access token or refresh an expired token.
This method handles two OAuth flows:
- Initial token exchange: Exchange authorization code for access/refresh tokens
- Token refresh: Use refresh_token to get new access/refresh tokens
122 123 124 125 126 127 128 129 130 |
# File 'lib/strava/oauth/client.rb', line 122 def oauth_token( = {}) query = .merge( client_id: client_id || raise(ArgumentError, 'Missing Strava client id.'), client_secret: client_secret || raise(ArgumentError, 'Missing Strava client secret.'), grant_type: [:grant_type] || 'authorization_code' ) Strava::Models::Token.new(post('token', query)) end |