Class: MaisOrcidClient::Authenticator

Inherits:
Object
  • Object
show all
Defined in:
lib/mais_orcid_client/authenticator.rb

Overview

The namespace for the “login” command

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client_id, client_secret, base_url) ⇒ Authenticator

Returns a new instance of Authenticator.



12
13
14
15
16
# File 'lib/mais_orcid_client/authenticator.rb', line 12

def initialize(client_id, client_secret, base_url)
  @client_id = client_id
  @client_secret = client_secret
  @base_url = base_url
end

Instance Attribute Details

#base_urlObject (readonly)

Returns the value of attribute base_url.



6
7
8
# File 'lib/mais_orcid_client/authenticator.rb', line 6

def base_url
  @base_url
end

#client_idObject (readonly)

Returns the value of attribute client_id.



6
7
8
# File 'lib/mais_orcid_client/authenticator.rb', line 6

def client_id
  @client_id
end

#client_secretObject (readonly)

Returns the value of attribute client_secret.



6
7
8
# File 'lib/mais_orcid_client/authenticator.rb', line 6

def client_secret
  @client_secret
end

Class Method Details

.token(client_id, client_secret, base_url) ⇒ Object



8
9
10
# File 'lib/mais_orcid_client/authenticator.rb', line 8

def self.token(client_id, client_secret, base_url)
  new(client_id, client_secret, base_url).token
end

Instance Method Details

#tokenString

Returns:

  • (String)


19
20
21
22
23
24
# File 'lib/mais_orcid_client/authenticator.rb', line 19

def token
  client = OAuth2::Client.new(client_id, client_secret, site: base_url,
    token_url: "/api/oauth/token", authorize_url: "/api/oauth/authorize",
    auth_scheme: :request_body)
  client.client_credentials.get_token.token
end