Module: Fog::Brightbox::OAuth2
- Included in:
- Compute::Shared
- Defined in:
- lib/fog/brightbox/oauth2.rb
Overview
This module covers Brightbox’s partial implementation of OAuth 2.0 and enables fog clients to implement several authentictication strategies
Defined Under Namespace
Classes: ClientCredentialsStrategy, CredentialSet, GrantTypeStrategy, RefreshTokenStrategy, TwoFactorMissingError, UserCredentialsStrategy
Constant Summary collapse
- TWO_FACTOR_HEADER =
"X-Brightbox-OTP".freeze
Instance Method Summary collapse
-
#request_access_token(connection, credentials) ⇒ Excon::Response
This builds the simplest form of requesting an access token based on the arguments passed in.
Instance Method Details
#request_access_token(connection, credentials) ⇒ Excon::Response
This builds the simplest form of requesting an access token based on the arguments passed in
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/fog/brightbox/oauth2.rb', line 24 def request_access_token(connection, credentials) token_strategy = credentials.best_grant_strategy if two_factor? # When 2FA opt-in is set, we can expect 401 responses as well response = connection.request( path: "/token", expects: [200, 401], headers: token_strategy.headers, method: "POST", body: Fog::JSON.encode(token_strategy.) ) if response.status == 401 && response.headers[Fog::Brightbox::OAuth2::TWO_FACTOR_HEADER] == "required" raise TwoFactorMissingError elsif response.status == 401 raise Excon::Errors.status_error({ expects: 200 }, status: 401) else response end else # Use classic behaviour and return Excon:: connection.request( path: "/token", expects: 200, headers: token_strategy.headers, method: "POST", body: Fog::JSON.encode(token_strategy.) ) end end |