oauth: add HTMLSuccess + HTMLError fields for branded login pages#330
Closed
davidlwg wants to merge 1 commit into
Closed
oauth: add HTMLSuccess + HTMLError fields for branded login pages#330davidlwg wants to merge 1 commit into
davidlwg wants to merge 1 commit into
Conversation
The htmlSuccess / htmlError templates are good defaults but shipped as unexported package vars, so callers can't brand the post-login landing page short of forking. Adds two optional fields on AuthorizationCodeTokenSource that override the defaults when set, and plumbs them through to authHandler via two matching unexported fields. When empty, the new fields are no-ops and the existing constants are served, so existing callers see no behaviour change. The custom error HTML supports the same $ERROR / $DETAILS substitution the built-in errorHTML does, so callers can reuse the documented format without having to learn two templating systems. Tests: five new cases in oauth/authcode_test.go covering default + custom success, default + custom error, and field independence (overriding success alone leaves the error path unaffected).
a181ae1 to
2474109
Compare
Collaborator
|
Superceded by #335, so closing this one. Thanks! |
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
Adds two optional fields,
HTMLSuccessandHTMLError, toAuthorizationCodeTokenSource. When set, they override the built-in success / error HTML pages served to the browser at the end of the OAuth callback flow. When empty (the default), behaviour is unchanged.The change is purely additive — no existing callers see different behaviour.
Why
The default
htmlSuccess/htmlErrortemplates are good general defaults, but they're shipped as unexported package-level vars, so downstream tools have no way to brand the post-login landing page short of forking the package. Branded CLIs (a fairly common use ofAuthorizationCodeTokenSource) currently have to choose between using restish's PKCE flow and showing their own success / error UI, even though everything else about the flow is already factored out as configurable.A motivating example: I'm building a corporate-internal CLI on top of restish where the post-login page should show the user "logged in as to " and the team's brand. Today the user just sees the generic restish "Login Successful!" page, which works fine but feels unbranded. With this change, callers configure the HTML alongside the URL / scope / client config:
Implementation
Three small touches in
oauth/authcode.go:AuthorizationCodeTokenSource(HTMLSuccess,HTMLError) with doc comments documenting the$ERROR/$DETAILSsubstitution behaviour for the error path.authHandler(successHTML,errorHTML) and a default-when-empty fallback inServeHTTPthat selects the override when set, otherwise the existing package-level constants.Token()to pass the user-provided HTML into the handler at construction time.Tests
Five new tests in
oauth/authcode_test.gocover:htmlSuccessserved whensuccessHTMLis unsetsuccessHTMLis sethtmlErrorserved with$ERROR/$DETAILSsubstitution whenerrorHTMLis unseterrorHTMLis setgo test ./oauth/...passes locally (6 tests including the existingTestEncodeUrlWindowsSuccess).Compatibility
Pure addition. Existing callers see no behaviour change — the new fields default to empty strings, which routes through the existing constants. No public API removed or renamed. Safe to merge under semver.