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

feat: include grant type error #144

Merged
merged 1 commit into from
Oct 2, 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
3 changes: 2 additions & 1 deletion access_request_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ func (f *Fosite) NewAccessRequest(ctx context.Context, r *http.Request, session
}

if !found {
return nil, errorsx.WithStack(ErrInvalidRequest)
return nil, errorsx.WithStack(ErrInvalidRequest.WithDebugf("The client with id '%s' requested grant type '%s' which is invalid, unknown, not supported, or not configured to be handled.", accessRequest.GetRequestForm().Get(consts.FormParameterClientID), strings.Join(accessRequest.GetGrantTypes(), " ")))
}

return accessRequest, nil
}
8 changes: 6 additions & 2 deletions access_request_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,14 @@ func TestNewAccessRequest(t *testing.T) {
header: http.Header{},
method: "POST",
form: url.Values{
consts.FormParameterClientID: {"bar"},
consts.FormParameterGrantType: {"foo"},
},
mock: func(ctx gomock.Matcher, handler *mock.MockTokenEndpointHandler, store *mock.MockStorage, hasher *mock.MockHasher, client *DefaultClient) {
store.EXPECT().GetClient(ctx, gomock.Eq("bar")).Return(&DefaultClient{ID: "bar"}, nil)
},
expectErr: ErrInvalidRequest,
expectStrErr: "The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Make sure that the various parameters are correct, be aware of case sensitivity and trim your parameters. Make sure that the client you are using has exactly whitelisted the redirect_uri you specified.",
expectStrErr: "The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Make sure that the various parameters are correct, be aware of case sensitivity and trim your parameters. Make sure that the client you are using has exactly whitelisted the redirect_uri you specified. The client with id 'bar' requested grant type 'foo' which is invalid, unknown, not supported, or not configured to be handled.",
},
{
name: "ShouldReturnInvalidRequestWhenEmptyClientID",
Expand All @@ -60,7 +64,7 @@ func TestNewAccessRequest(t *testing.T) {
consts.FormParameterClientID: {""},
},
expectErr: ErrInvalidRequest,
expectStrErr: "The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Make sure that the various parameters are correct, be aware of case sensitivity and trim your parameters. Make sure that the client you are using has exactly whitelisted the redirect_uri you specified.",
expectStrErr: "The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Make sure that the various parameters are correct, be aware of case sensitivity and trim your parameters. Make sure that the client you are using has exactly whitelisted the redirect_uri you specified. The client with id '' requested grant type 'foo' which is invalid, unknown, not supported, or not configured to be handled.",
},
{
name: "ShouldReturnInvalidClientWhenGetClientError",
Expand Down
Loading