Skip to content

Commit

Permalink
feat: makeRemoveEmpty public (#443)
Browse files Browse the repository at this point in the history
  • Loading branch information
mitar authored Jun 5, 2020
1 parent c06e560 commit 17b0756
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions access_request_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ func (f *Fosite) NewAccessRequest(ctx context.Context, r *http.Request, session
return accessRequest, errors.New("Session must not be nil")
}

accessRequest.SetRequestedScopes(removeEmpty(strings.Split(r.PostForm.Get("scope"), " ")))
accessRequest.SetRequestedAudience(removeEmpty(strings.Split(r.PostForm.Get("audience"), " ")))
accessRequest.GrantTypes = removeEmpty(strings.Split(r.PostForm.Get("grant_type"), " "))
accessRequest.SetRequestedScopes(RemoveEmpty(strings.Split(r.PostForm.Get("scope"), " ")))
accessRequest.SetRequestedAudience(RemoveEmpty(strings.Split(r.PostForm.Get("audience"), " ")))
accessRequest.GrantTypes = RemoveEmpty(strings.Split(r.PostForm.Get("grant_type"), " "))
if len(accessRequest.GrantTypes) < 1 {
return accessRequest, errors.WithStack(ErrInvalidRequest.WithHint(`Request parameter "grant_type"" is missing`))
}
Expand Down
4 changes: 2 additions & 2 deletions authorize_request_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,14 @@ func (f *Fosite) validateResponseTypes(r *http.Request, request *AuthorizeReques
// values, where the order of values does not matter (e.g., response
// type "a b" is the same as "b a"). The meaning of such composite
// response types is defined by their respective specifications.
responseTypes := removeEmpty(stringsx.Splitx(r.Form.Get("response_type"), " "))
responseTypes := RemoveEmpty(stringsx.Splitx(r.Form.Get("response_type"), " "))
if len(responseTypes) == 0 {
return errors.WithStack(ErrUnsupportedResponseType.WithHint(`The request is missing the "response_type"" parameter.`))
}

var found bool
for _, t := range request.GetClient().GetResponseTypes() {
if Arguments(responseTypes).Matches(removeEmpty(stringsx.Splitx(t, " "))...) {
if Arguments(responseTypes).Matches(RemoveEmpty(stringsx.Splitx(t, " "))...) {
found = true
break
}
Expand Down
2 changes: 1 addition & 1 deletion helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func StringInSlice(needle string, haystack []string) bool {
return false
}

func removeEmpty(args []string) (ret []string) {
func RemoveEmpty(args []string) (ret []string) {
for _, v := range args {
v = strings.TrimSpace(v)
if v != "" {
Expand Down
2 changes: 1 addition & 1 deletion introspection_request_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (f *Fosite) NewIntrospectionRequest(ctx context.Context, r *http.Request, s
}
}

tt, ar, err := f.IntrospectToken(ctx, token, TokenType(tokenType), session, strings.Split(scope, " ")...)
tt, ar, err := f.IntrospectToken(ctx, token, TokenType(tokenType), session, RemoveEmpty(strings.Split(scope, " "))...)
if err != nil {
return &IntrospectionResponse{Active: false}, errors.WithStack(ErrInactiveToken.WithHint("An introspection strategy indicated that the token is inactive.").WithDebug(err.Error()))
}
Expand Down

0 comments on commit 17b0756

Please sign in to comment.