module FidorApi::Client::Authentication
Attributes
token[RW]
Public Instance Methods
client_login()
click to toggle source
oAuth2 - Client
Credentials Flow
# File lib/fidor_api/client/authentication.rb, line 18 def client_login check_flow_support! :client_credentials self.token = oauth_token(grant_type: 'client_credentials') end
login(username:, password:, grant_type: 'password')
click to toggle source
oAuth2 - Resource Owner Password Grant Flow
# File lib/fidor_api/client/authentication.rb, line 7 def login(username:, password:, grant_type: 'password') check_flow_support! :resource_owner_password_credentials self.token = oauth_token( grant_type: grant_type, username: username, password: password ) end
Private Instance Methods
check_flow_support!(symbol)
click to toggle source
# File lib/fidor_api/client/authentication.rb, line 47 def check_flow_support!(symbol) raise Errors::NotSupported \ unless config.environment.auth_methods.include? symbol end
oauth_token(**body)
click to toggle source
# File lib/fidor_api/client/authentication.rb, line 52 def oauth_token(**body) response = connection(host: config.environment.auth_host).post( '/oauth/token', body: body, auth: [config.client_id, config.client_secret] ) Token.new(response.body) end