module Trubl::OAuth
Public Instance Methods
client_auth()
click to toggle source
implements client_credentials access_token retrieval
# File lib/trubl/oauth.rb, line 8 def client_auth() url = URI.join(@auth_site, @token_url).to_s body = { client_id: @client_id, client_secret: @client_secret, grant_type: "client_credentials" } Trubl.logger.info("Trubl::OAuth post-ing #{url} with params #{{body: body, headers: headers}}") response = HTTParty.send(:post, url, body: body, headers: headers) Trubl.logger.debug("Trubl::OAuth #{url} response: #{response.code} #{response.body}") if response.code == 200 and JSON.parse(response.body)["access_token"].present? @access_token = JSON.parse(response.body)["access_token"] else raise "Client failed to get an auth token, response was: " + response.body end end
password_auth(opts={})
click to toggle source
ToDo: add some param checking logic
# File lib/trubl/oauth.rb, line 28 def password_auth(opts={}) url = URI.join(@auth_site, @token_url).to_s body = { client_id: @client_id, client_secret: @client_secret, email: @email, password: @password, # scope: "read write share", scope: "read write share update_auth", grant_type: "password" }.merge(opts) Trubl.logger.info("Trubl::OAuth post-ing #{url} with params #{{body: body, headers: headers}}") response = HTTParty.send(:post, url, body: body, headers: headers) Trubl.logger.debug("Trubl::OAuth #{url} response: #{response.code} #{response.body}") if response.code == 200 and JSON.parse(response.body)["access_token"].present? @access_token = JSON.parse(response.body)["access_token"] else raise "Client failed to get an auth token, response was: " + response.body end end
Also aliased as: user_auth