Skip to content
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

Add screen hint to GetAuthorizationURLOpts #319

Merged
merged 4 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions pkg/usermanagement/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ import (
// ResponseLimit is the default number of records to limit a response to.
const ResponseLimit = 10

// ScreenHint represents the screen to redirect the user to in Authkit
type ScreenHint string

// Constants that enumerate the available screen hints.
const (
SignUp ScreenHint = "sign-up"
SignIn ScreenHint = "sign-in"
)

// Order represents the order of records.
type Order string

Expand Down Expand Up @@ -702,6 +711,10 @@ type GetAuthorizationURLOpts struct {
// Domain hint that will be passed as a parameter to the IdP login page.
// OPTIONAL.
DomainHint string

// ScreenHint represents the screen to redirect the user to when the provider is Authkit.
// OPTIONAL.
ScreenHint ScreenHint
}

// GetAuthorizationURL generates an OAuth 2.0 authorization URL.
Expand Down Expand Up @@ -743,6 +756,13 @@ func (c *Client) GetAuthorizationURL(opts GetAuthorizationURLOpts) (*url.URL, er
query.Set("state", opts.State)
}

if opts.ScreenHint != "" {
if opts.Provider != "authkit" {
return nil, errors.New("provider must be 'authkit' to include a screen hint")
}
query.Set("screen_hint", string(opts.ScreenHint))
}

u, err := url.ParseRequestURI(c.Endpoint + "/user_management/authorize")
if err != nil {
return nil, err
Expand Down
10 changes: 10 additions & 0 deletions pkg/usermanagement/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,16 @@ func TestClientAuthorizeURL(t *testing.T) {
},
expected: "https://api.workos.com/user_management/authorize?client_id=client_123&provider=GoogleOAuth&redirect_uri=https%3A%2F%2Fexample.com%2Fsso%2Fworkos%2Fcallback&response_type=code&state=custom+state",
},
{
scenario: "generate url with a screen hint",
options: GetAuthorizationURLOpts{
ClientID: "client_123",
Provider: "authkit",
RedirectURI: "https://example.com/sso/workos/callback",
ScreenHint: "sign-up",
},
expected: "https://api.workos.com/user_management/authorize?client_id=client_123&provider=authkit&redirect_uri=https%3A%2F%2Fexample.com%2Fsso%2Fworkos%2Fcallback&response_type=code&screen_hint=sign-up",
},
{
scenario: "generate url with connection",
options: GetAuthorizationURLOpts{
Expand Down
Loading