Skip to content

Commit 125b97b

Browse files
committed
feat: enhance invitation code handling in authorization flow
- Updated WithInvitationCode function to set the prompt parameter to "create" when an invitation code is provided. - Added assertions in tests to verify that the prompt is correctly set in authURLOptions and included in the generated authentication URL. - Improved test coverage for scenarios involving invitation codes, ensuring proper handling of the prompt parameter.
1 parent 3f01bb5 commit 125b97b

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

oauth2/authorization_code/authorization_code_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,16 @@ func TestWithInvitationCodeOption(t *testing.T) {
143143
assert.Contains(isInvitationValues, "true", "is_invitation should be set to 'true'")
144144
}
145145

146+
promptValues, hasPrompt := flow.authURLOptions["prompt"]
147+
assert.True(hasPrompt, "prompt should be set in authURLOptions when invitation code is provided")
148+
if hasPrompt {
149+
assert.Contains(promptValues, "create", "prompt should be 'create' when invitation code is provided")
150+
}
151+
146152
authURL := kindeAuthFlow.GetAuthURL()
147153
assert.Contains(authURL, "invitation_code=inv_987654321", "AuthURL should contain invitation_code parameter")
148154
assert.Contains(authURL, "is_invitation=true", "AuthURL should contain is_invitation parameter")
155+
assert.Contains(authURL, "prompt=create", "AuthURL should contain prompt=create parameter")
149156
}
150157

151158
func TestWithInvitationCodeOptionEmpty(t *testing.T) {
@@ -165,8 +172,10 @@ func TestWithInvitationCodeOptionEmpty(t *testing.T) {
165172
flow := kindeAuthFlow.(*AuthorizationCodeFlow)
166173
_, hasInvitationCode := flow.authURLOptions["invitation_code"]
167174
_, hasIsInvitation := flow.authURLOptions["is_invitation"]
175+
_, hasPrompt := flow.authURLOptions["prompt"]
168176
assert.False(hasInvitationCode, "invitation_code should not be set when empty")
169177
assert.False(hasIsInvitation, "is_invitation should not be set when empty")
178+
assert.False(hasPrompt, "prompt should not be set when invitation code is empty")
170179
}
171180

172181
func TestWithInvitationCodeOptionOverwrite(t *testing.T) {
@@ -203,6 +212,14 @@ func TestWithInvitationCodeOptionOverwrite(t *testing.T) {
203212
assert.Len(isInvitationValues, 1, "is_invitation should have only one value")
204213
assert.Contains(isInvitationValues, "true", "is_invitation should be 'true'")
205214
}
215+
216+
promptValues, hasPrompt := flow.authURLOptions["prompt"]
217+
assert.True(hasPrompt, "prompt should be set in authURLOptions when invitation code is provided")
218+
if hasPrompt {
219+
// Should only have one value
220+
assert.Len(promptValues, 1, "prompt should have only one value")
221+
assert.Contains(promptValues, "create", "prompt should be 'create' when invitation code is provided")
222+
}
206223
}
207224

208225
func getTestAuthorizationServer() *httptest.Server {

oauth2/authorization_code/options.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,14 @@ func WithPKCEChallengeMethod(method string) Option {
144144
}
145145

146146
// WithInvitationCode sets the invitation code and is_invitation parameters for team member invitations.
147-
// When an invitation code is provided, is_invitation will be set to "true".
147+
// When an invitation code is provided, is_invitation will be set to "true" and prompt will be set to "create".
148148
// If called multiple times, it will overwrite the previous values instead of accumulating them.
149149
func WithInvitationCode(invitationCode string) Option {
150150
return func(s *AuthorizationCodeFlow) {
151151
if invitationCode != "" {
152152
s.authURLOptions.Set("invitation_code", invitationCode)
153153
s.authURLOptions.Set("is_invitation", "true")
154+
s.authURLOptions.Set("prompt", "create")
154155
}
155156
}
156157
}

0 commit comments

Comments
 (0)