Class: AuthenticationService

Inherits:
Object
  • Object
show all
Defined in:
lib/services/authentication_service.rb

Constant Summary collapse

@@authentication_url =
'https://showoff-rails-react-production.herokuapp.com/oauth/token'
@@revoke_url =
'https://showoff-rails-react-production.herokuapp.com/oauth/revoke'

Class Method Summary collapse

Class Method Details

.create_auth_dataObject

to remove once tested



37
38
39
40
41
42
43
44
45
# File 'lib/services/authentication_service.rb', line 37

def self.create_auth_data
    auth = Authentication.new
    auth.grant_type = "password"
   # auth.client_id = "277ef29692f9a70d511415dc60592daf4cf2c6f6552d3e1b769924b2f2e2e6fe"
    #auth.client_secret = "d6106f26e8ff5b749a606a1fba557f44eb3dca8f48596847770beb9b643ea352"
    auth.username = "[email protected]"
    auth.password = "password"
    return auth
end

.create_authentication(auth_data) ⇒ Object



10
11
12
13
14
15
# File 'lib/services/authentication_service.rb', line 10

def self.create_authentication(auth_data)
    auth_data = get_auth_with_client_info(auth_data)
    auth_payload = Authentication.get_payload(auth_data)
    return RestClient::Request.execute(method: :post, url: @@authentication_url,
        payload: auth_payload, headers: {'Content-Type': 'application/json'})
end

.get_access_tokenObject

remove once tested



48
49
50
51
52
53
54
# File 'lib/services/authentication_service.rb', line 48

def self.get_access_token
    auth_data = AuthenticationService.create_auth_data
    authJson = AuthenticationService.create_authentication(auth_data)
    res_data = JSON.parse(authJson)
    access_token =  res_data['data']['token']['access_token']
    return access_token
end

.get_auth_with_client_info(auth_data) ⇒ Object



30
31
32
33
34
# File 'lib/services/authentication_service.rb', line 30

def self.get_auth_with_client_info(auth_data)
    auth_data.client_id = ApplicationConfig.get_client_id
    auth_data.client_secret = ApplicationConfig.get_client_secret
    return auth_data
end

.refresh_authentication_token(auth_data, bearer_token) ⇒ Object



17
18
19
20
21
22
# File 'lib/services/authentication_service.rb', line 17

def self.refresh_authentication_token(auth_data, bearer_token)
    auth_data = get_auth_with_client_info(auth_data)
    auth_payload = Authentication.get_payload(auth_data)
    return RestClient::Request.execute(method: :post, url: @@authentication_url,
        payload: auth_payload, headers: {'Content-Type': 'application/json', 'Authorization': bearer_token})
end

.revoke_authentication_token(auth_data, bearer_token) ⇒ Object



24
25
26
27
28
# File 'lib/services/authentication_service.rb', line 24

def self.revoke_authentication_token(auth_data, bearer_token)
    auth_payload = Authentication.get_payload(auth_data)
    return RestClient::Request.execute(method: :post, url: @@revoke_url,
        payload: auth_payload, headers: {'Content-Type': 'application/json', 'Authorization': bearer_token})
end