class OAuth2::Strategy::ClientCredentials

The Client Credentials Strategy

@see tools.ietf.org/html/draft-ietf-oauth-v2-15#section-4.4

The Client Credentials Strategy

@see tools.ietf.org/html/draft-ietf-oauth-v2-15#section-4.4

Public Instance Methods

authorization(client_id, client_secret) click to toggle source

Returns the Authorization header value for Basic Authentication

@param [String] The client ID @param [String] the client secret

# File lib/oauth2-cocoa/strategy/client_credentials.rb, line 11
def authorization(client_id, client_secret)
  encoder = CocoaSecurityEncoder.new
  authorization = encoder.base64("#{client_id}:#{client_secret}".to_data).gsub("\n", "")
  "Basic #{authorization}"
end
authorize_url() click to toggle source

Not used for this strategy

@raise [NotImplementedError]

# File lib/oauth2/strategy/client_credentials.rb, line 10
def authorize_url
  fail(NotImplementedError, "The authorization endpoint is not used in this strategy")
end
get_token(params = {}, opts = {}) click to toggle source

Retrieve an access token given the specified client.

@param [Hash] params additional params @param [Hash] opts options

# File lib/oauth2/strategy/client_credentials.rb, line 18
def get_token(params = {}, opts = {})
  request_body = opts.delete("auth_scheme") == "request_body"
  params.merge!("grant_type" => "client_credentials")
  params.merge!(request_body ? client_params : {
    headers: {
      "Authorization" => authorization(client_params["client_id"], client_params["client_secret"])
    }
  })
  @client.get_token(params, opts.merge("refresh_token" => nil))
end