Repository navigation
Return the standard token fields as credentials, and leave expiry to the app - #1
Merged
Merged
Conversation
…the app credentials now carries the token response's standard fields: token_type and scope as well as the tokens and their expiry, and the refresh token's own expiry when the vendor says. That is read from refresh_token_timeout, the IETF draft's name, or refresh_token_expires_in, which GitHub, Google and Shopify send; most vendors send neither. HubSpot's scopes list becomes scope. Other fields stay out, as the libraries that persist credentials keep a fixed set: vendors put secrets and personal data under names log filters miss. Expiries are epoch seconds, as oauth2 and OmniAuth keep them, so the credentials hash stores oauth2's value as it is. An expires_at that 0.1.0 stored as ISO 8601 text still refreshes. refresh always asks the vendor, and expired? and refresh! are gone: an app renews when it chooses, a couple of minutes before expires_at, or before the refresh token runs out to keep idle credentials alive.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
credentials now carries the token response's standard fields, with expiries as epoch seconds, and an app decides for itself when to refresh.
What changes
access_token,token_type,refresh_token,expires_at,refresh_token_expires_atandscope. Keys a vendor doesn't send are left out.refresh_token_expires_atcomes fromrefresh_token_timeout, the IETF draft's name, orrefresh_token_expires_in, which GitHub, Google and Shopify send. Most vendors send neither, so a missing value doesn't mean the refresh token never runs out.scopeslist becomesscope, the standard space-separated string.expires_atthat 0.1.0 stored as text still refreshes, because oauth2'sfrom_hashparses it.refresh(credentials)always asks the vendor.expired?andrefresh!are removed. The app renews a couple of minutes beforeexpires_at, or beforerefresh_token_expires_atto keep idle credentials alive.expiresflag, unlike OmniAuth: it repeatsexpires_at, and oauth2'sfrom_hashcrashes onexpires: true.docs/how-a-sign-in-works.md, the Shopify and HubSpot strategy pages and the CHANGELOG are updated, and the version is 0.2.0.Why
authed_usertokens and webhookurl, a Shopify staff member's email, Salesforce'ssignature. Auth.js, Spring, Go's x/oauth2, Google's libraries and MSAL all persist a fixed set for the same reason.token_typeandscopeare kept because RFC 6749 says a client must not use a token type it doesn't understand, and a grant can come back with fewer scopes than were asked for.credentials_fromstores its value as it is.Upgrading
refresh(credentials)keeps its name but now always asks the vendor. In 0.1.0 it asked only when the token was about to expire, so an app that calls it before every use would refresh on every call. Checkexpires_atfirst.strategy.expired?(credentials)with your own check, for examplecredentials['expires_at'] < 2.minutes.from_now.to_i, then callstrategy.refresh(credentials).expires_atas ISO 8601 text until they've refreshed once. Convert them before comparing:Time.iso8601(expires_at).to_i if expires_at.is_a?(String).Time.at(...)instead of.to_time.Connectors::Basecallsexpired?and needs the same.Tests
138 runs, 0 failures (
bundle exec rake teston Ruby 4.0).