Module: Typetalk::Api::Auth
- Included in:
- Typetalk::Api
- Defined in:
- lib/typetalk/api/auth.rb
Instance Attribute Summary collapse
-
#authorization_code ⇒ Object
Returns the value of attribute authorization_code.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#authorization_code ⇒ Object
Returns the value of attribute authorization_code.
5 6 7 |
# File 'lib/typetalk/api/auth.rb', line 5 def @authorization_code end |
Class Method Details
.authorize_url(options = {}) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/typetalk/api/auth.rb', line 48 def self.(={}) = {client_id:nil, redirect_uri:nil, scope:nil}.merge() params = { client_id: [:client_id] || Typetalk.config.client_id, redirect_uri: [:redirect_uri] || Typetalk.config.redirect_uri, scope: [:scope] || Typetalk.config.scope, response_type: 'code', } url = URI.parse('https://typetalk.com/oauth2/authorize') url.query = URI.encode_www_form(params) url.to_s end |
Instance Method Details
#get_access_token(options = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/typetalk/api/auth.rb', line 7 def get_access_token(={}) = {client_id:nil, client_secret:nil, grant_type:nil, scope:nil, code:nil, redirect_uri:nil}.merge() body = { client_id: [:client_id] || Typetalk.config.client_id, client_secret: [:client_secret] || Typetalk.config.client_secret, grant_type: [:grant_type] || Typetalk.config.grant_type, scope: [:scope] || Typetalk.config.scope, } if body[:grant_type] == 'authorization_code' body[:code] = [:code] || @authorization_code body[:redirect_uri] = [:redirect_uri] || Typetalk.config.redirect_uri end response = connection.post do |req| req.url 'https://typetalk.com/oauth2/access_token' req.body = body end parse_response(response) end |
#update_access_token(refresh_token, options = {}) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/typetalk/api/auth.rb', line 30 def update_access_token(refresh_token, ={}) = {client_id:nil, client_secret:nil}.merge() body = { client_id: [:client_id] || Typetalk.config.client_id, client_secret: [:client_secret] || Typetalk.config.client_secret, grant_type: 'refresh_token', refresh_token: refresh_token } response = connection.post do |req| req.url 'https://typetalk.com/oauth2/access_token' req.body = body end parse_response(response) end |