Class: NulogySSO::CookieTokenStore

Inherits:
Object
  • Object
show all
Defined in:
app/services/nulogy_sso/cookie_token_store.rb

Overview

A class for storing the SSO token in cookies

This uses the Rack level API instead of going through the Rails API because we have found that for our GraphQL based applications, using the cookiejar API has not been working. The cookies are not being set correctly, likely because the requests are resulting in 302 redirects.

Instance Method Summary collapse

Constructor Details

#initialize(request, response) ⇒ CookieTokenStore

Returns a new instance of CookieTokenStore.



9
10
11
12
# File 'app/services/nulogy_sso/cookie_token_store.rb', line 9

def initialize(request, response)
  @request = request
  @response = response
end

Instance Method Details

#fetchObject



14
15
16
# File 'app/services/nulogy_sso/cookie_token_store.rb', line 14

def fetch
  @request.cookie_jar[NulogySSO.sso_cookie_key]
end

#forget!Object



30
31
32
33
34
35
36
# File 'app/services/nulogy_sso/cookie_token_store.rb', line 30

def forget!
  @response.delete_cookie(
    NulogySSO.sso_cookie_key,
    path: "/",
    domain: all_domains
  )
end

#store!(access_token_value) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'app/services/nulogy_sso/cookie_token_store.rb', line 18

def store!(access_token_value)
  @response.set_cookie(
    NulogySSO.sso_cookie_key,
    value: access_token_value,
    path: "/",
    domain: all_domains,
    expires: 36_000.seconds.from_now, # TODO: Fetch this value from the JWT
    httponly: true,
    secure: @request.ssl?
  )
end