Repository navigation
feat(user): add User#resource_token for delegated SSO access - #333
Merged
Merged
Conversation
Moves the SSO resource token logic out of rest-api so other services (staff-api) can obtain a user's delegated token directly instead of making an intra-service request. The stored access token is returned while it has more than five minutes remaining, otherwise it is refreshed against the authority's OAuth strategy and saved. A token that hasn't expired yet is still returned if the refresh fails. Raises `Error::NoResourceToken` when there is nothing to refresh with. Relative `token_url`s are now resolved against the strategy's `site`. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This was referenced Oct 8, 2026
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.
Summary
User#resource_token(authority = user.authority) : User::ResourceToken. This is rest-api'sApi::Users.get_user_tokenmoved into models, so staff-api can get a user's delegated SSO token (MS Graph / Google) without calling rest-api.Model::Error::NoResourceToken, raised when there's no refresh token or no OAuth strategy. rest-api currently returns a 404 in that case.oauth-strategy(or the authority's first strategy) and saved.token_url(e.g. the default/oauth/token) is now resolved against the strategy'ssite. Previously it crashed onhostname.not_nil!. The token endpoint's scheme and port are now respected too.Part of removing staff-api's intra-service calls to rest-api. Follow-ups: staff-api and rest-api will use this method.
Test plan
./test spec/user_resource_token_spec.cr spec/user_spec.cr: 44 examples, 0 failures. Covers non-expiring / fresh / near-expiry refresh, refresh-token rotation, configured strategy, fallback within the drift window, raise when expired, no refresh token, and no strategy. Uses a local HTTP token server.🤖 Generated with Claude Code