Skip to content

Commit

Permalink
Add screen hint to GetAuthorizationURLOpts (#319)
Browse files Browse the repository at this point in the history
* Add screen hint
  • Loading branch information
hadihallak authored Mar 29, 2024
1 parent 306d604 commit 57bb3a5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
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

0 comments on commit 57bb3a5

Please sign in to comment.