Skip to content

Commit dd62a2a

Browse files
committed
feat: enhance prompt handling in GetAuthURLWithInvitation
- Updated GetAuthURLWithInvitation to set the prompt parameter to "create" only if no custom prompt is provided. - Added tests to verify that the prompt parameter behaves correctly with and without invitation codes, ensuring custom prompts are preserved. - Improved test coverage for scenarios involving invitation codes and prompt handling.
1 parent 125b97b commit dd62a2a

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

oauth2/authorization_code/authorization_code.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ func (flow *AuthorizationCodeFlow) GetAuthURLWithInvitation(invitationCode strin
157157
if invitationCode != "" {
158158
query.Set("invitation_code", invitationCode)
159159
query.Set("is_invitation", "true")
160+
if query.Get("prompt") == "" {
161+
query.Set("prompt", "create")
162+
}
160163
}
161164

162165
// Add PKCE parameters if enabled

oauth2/authorization_code/authorization_code_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,25 @@ func TestGetAuthURLWithInvitation(t *testing.T) {
107107
assert.NotEmpty(authURL, "AuthURL cannot be empty")
108108
assert.Contains(authURL, "invitation_code=inv_123456789", "AuthURL should contain invitation_code parameter")
109109
assert.Contains(authURL, "is_invitation=true", "AuthURL should contain is_invitation parameter")
110+
assert.Contains(authURL, "prompt=create", "AuthURL should contain prompt=create parameter when invitation code is provided")
110111

111112
// Test without invitation code (empty string)
112113
authURLNoInvitation := kindeAuthFlow.GetAuthURLWithInvitation("")
113114
assert.NotEmpty(authURLNoInvitation, "AuthURL cannot be empty")
114115
assert.NotContains(authURLNoInvitation, "invitation_code", "AuthURL should not contain invitation_code when empty")
115116
assert.NotContains(authURLNoInvitation, "is_invitation", "AuthURL should not contain is_invitation when empty")
117+
assert.NotContains(authURLNoInvitation, "prompt=create", "AuthURL should not contain prompt=create when invitation code is empty")
118+
119+
// Test that existing prompt value is not overwritten
120+
kindeAuthFlowWithPrompt, _ := NewAuthorizationCodeFlow(
121+
testKindeServerURL, "b9da18c441b44d81bab3e8232de2e18d", "client_secret", callbackURL,
122+
WithSessionHooks(newTestSessionHooks()),
123+
WithCustomStateGenerator(func(*AuthorizationCodeFlow) string { return "test_state" }),
124+
WithPrompt("login"), // Set a custom prompt
125+
)
126+
authURLWithCustomPrompt := kindeAuthFlowWithPrompt.GetAuthURLWithInvitation(invitationCode)
127+
assert.Contains(authURLWithCustomPrompt, "prompt=login", "AuthURL should preserve custom prompt value")
128+
assert.NotContains(authURLWithCustomPrompt, "prompt=create", "AuthURL should not overwrite custom prompt with create")
116129
}
117130

118131
func TestWithInvitationCodeOption(t *testing.T) {

0 commit comments

Comments
 (0)