Class: Mobiscroll::Connect::Resources::Auth
- Inherits:
-
Object
- Object
- Mobiscroll::Connect::Resources::Auth
- Defined in:
- lib/mobiscroll/connect/resources/auth.rb
Instance Method Summary collapse
- #disconnect(provider:, account: nil) ⇒ Object
- #generate_auth_url(user_id:, scope: nil, state: nil, providers: nil) ⇒ Object
- #get_connection_status ⇒ Object
- #get_token(code) ⇒ Object
-
#initialize(config, api_client) ⇒ Auth
constructor
A new instance of Auth.
- #set_credentials(tokens) ⇒ Object
Constructor Details
#initialize(config, api_client) ⇒ Auth
Returns a new instance of Auth.
9 10 11 12 |
# File 'lib/mobiscroll/connect/resources/auth.rb', line 9 def initialize(config, api_client) @config = config @api_client = api_client end |
Instance Method Details
#disconnect(provider:, account: nil) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/mobiscroll/connect/resources/auth.rb', line 59 def disconnect(provider:, account: nil) query = { 'provider' => provider } query['account'] = account if account begin parsed = @api_client.post('/oauth/disconnect', query: query, body: {}) rescue NotFoundError parsed = @api_client.post('/disconnect', query: query, body: {}) end DisconnectResponse.from_h(parsed) end |
#generate_auth_url(user_id:, scope: nil, state: nil, providers: nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/mobiscroll/connect/resources/auth.rb', line 14 def generate_auth_url(user_id:, scope: nil, state: nil, providers: nil) params = { 'response_type' => 'code', 'client_id' => @config.client_id, 'redirect_uri' => @config.redirect_uri, 'user_id' => user_id } params['scope'] = scope if scope params['state'] = state if state query = URI.encode_www_form(params) if providers && !providers.empty? provider_params = providers.map { |p| "providers=#{URI.encode_www_form_component(p)}" }.join('&') query = "#{query}&#{provider_params}" end "#{@config.base_url}/oauth/authorize?#{query}" end |
#get_connection_status ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/mobiscroll/connect/resources/auth.rb', line 50 def get_connection_status begin parsed = @api_client.get('/oauth/connection-status') rescue NotFoundError parsed = @api_client.get('/connection-status') end ConnectionStatus.from_h(parsed) end |
#get_token(code) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/mobiscroll/connect/resources/auth.rb', line 34 def get_token(code) form = { 'grant_type' => 'authorization_code', 'code' => code, 'redirect_uri' => @config.redirect_uri } parsed = @api_client.post_form('/oauth/token', form) tokens = TokenResponse.from_h(parsed) @api_client.set_credentials(tokens) tokens end |
#set_credentials(tokens) ⇒ Object
46 47 48 |
# File 'lib/mobiscroll/connect/resources/auth.rb', line 46 def set_credentials(tokens) @api_client.set_credentials(tokens) end |