-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get token from cookie when using /login-with-expiry in Poppy #105
Conversation
@@ -151,7 +154,14 @@ def connection | |||
url: config.url, | |||
headers: DEFAULT_HEADERS.merge(config.okapi_headers || {}), | |||
request: { timeout: config.timeout } | |||
) | |||
) do |faraday| | |||
faraday.use :cookie_jar, jar: cookie_jar |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To access cookies directly, need to pass in a CookieJar.
@@ -276,8 +286,9 @@ def with_token_refresh_when_unauthorized | |||
response = yield | |||
|
|||
# if unauthorized, token has likely expired. try to get a new token and then retry the same request(s). | |||
if response.status == 401 | |||
config.token = Authenticator.token(config.login_params, connection) | |||
if response.status == 401 || response.status == 403 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FOLIO docs say that with Poppy release onward, if you send an expired token, it will return a 403 rather than a 401.
8a2c14d
to
3abe420
Compare
access_cookies = cookie_jar.cookies.select { |cookie| cookie.name == 'folioAccessToken' } | ||
access_cookies[0].value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we only care about the first value, we could consider Enumerable#find
here too:
access_cookies = cookie_jar.cookies.select { |cookie| cookie.name == 'folioAccessToken' } | |
access_cookies[0].value | |
cookie_jar.cookies.find { |cookie| cookie.name == 'folioAccessToken' }.value |
if legacy_auth | ||
JSON.parse(response.body)['okapiToken'] | ||
else | ||
access_cookies = cookie_jar.cookies.select { |cookie| cookie.name == 'folioAccessToken' } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we should handle the case where this line returns an empty array (in which case the #value
call immediately below will fail), or is that an unlikely/corner case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approve pending consideration of minor enumerable questions
Why was this change made? 🤔
Resolves #92 to implement new process for getting an access token.
Currently, the token is in the body of the response from the
/authn/login
endpoint. From Poppy onwards the token will be obtained from a/authn/login-with-expiry
endpoint and will be in a cookie. See the heading "A guide for non-module clients such as scripts or other integrations" on the Folio Wiki.How the token is sent to FOLIO in a request isn't changing. If an expired access token is sent in a request, FOLIO will return a 403 rather than a 401 as it does in Nolana/Orchid.
If we try to use the
login-with-expiry
endpoint on Nolana, FOLIO returns a 404. The EBSCO FOLIO client sends everything to that endpoint and if it gets a 404, it then tries thelogin
endpoint. I thought we might want more control over which endpoint we're sending requests to, especially since the docs say that both endpoints are supported in Poppy and Quesnalia (legacy tokens not removed until Ramsons). This has the downside that we are changing theFolioClient.configure
method signature and would want to eventually update that to remove thelegacy_auth
param with that is no longer relevant (once we've been on Poppy in production for a bit?).Will follow up with:
How was this change tested? 🤨
Unit. Tested that the changes do not break current usage by using
api_test.rb
locally and running thesdr_deposit_spec.rb
integration test anditem_creation_with_folio_hrid_spec.rb
when using this folio_client version on DSA and Argo QA.I haven't been able to test this on a live Poppy instance, so that would be good to do as soon as a Poppy dev/test instance is available (Libsys estimates in mid-January).