Skip to content

Commit

Permalink
oauth2: implicit handlers do not require tls over https (#61)
Browse files Browse the repository at this point in the history
closes #60
  • Loading branch information
arekkas committed Aug 1, 2016
1 parent 89c60c9 commit 6c40c08
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 5 deletions.
8 changes: 4 additions & 4 deletions authorize_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ func IsValidRedirectURI(redirectURI *url.URL) bool {
return false
}

if redirectURI.Scheme != "https" && !isLocalhost(redirectURI) {
return false
}

return true
}

func IsRedirectURISecure(redirectURI *url.URL) bool {
return !(redirectURI.Scheme != "https" && !isLocalhost(redirectURI))
}

func isLocalhost(redirectURI *url.URL) bool {
host := strings.Split(redirectURI.Host, ":")[0]
return host == "localhost" || host == "127.0.0.1"
Expand Down
4 changes: 4 additions & 0 deletions handler/core/explicit/explicit_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ func (c *AuthorizeExplicitGrantTypeHandler) HandleAuthorizeEndpointRequest(ctx c
return errors.Wrap(ErrInvalidGrant, "")
}

if !IsRedirectURISecure(ar.GetRedirectURI()) {
return errors.Wrap(ErrInvalidRequest, "")
}

return c.IssueAuthorizeCode(ctx, req, ar, resp)
}

Expand Down
10 changes: 9 additions & 1 deletion handler/core/explicit/explicit_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,18 @@ func TestHandleAuthorizeEndpointRequest(t *testing.T) {
},
},
{
description: "should fail because authorize code generation failed",
description: "should fail because redirect uri is not https",
setup: func() {
areq.ResponseTypes = fosite.Arguments{"code"}
areq.Client = &fosite.DefaultClient{ResponseTypes: fosite.Arguments{"code"}}
areq.RedirectURI, _ = url.Parse("http://asdf.de/cb")
},
expectErr: fosite.ErrInvalidRequest,
},
{
description: "should fail because authorize code generation failed",
setup: func() {
areq.RedirectURI, _ = url.Parse("https://foobar.com/cb")
chgen.EXPECT().GenerateAuthorizeCode(nil, areq).Return("", "", errors.New(""))
},
expectErr: fosite.ErrServerError,
Expand Down
3 changes: 3 additions & 0 deletions handler/core/implicit/implicit.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ func (c *AuthorizeImplicitGrantTypeHandler) HandleAuthorizeEndpointRequest(ctx c
return errors.Wrap(ErrInvalidGrant, "")
}

// there is no need to check for https, because implicit flow does not require https
// https://tools.ietf.org/html/rfc6819#section-4.4.2

return c.IssueImplicitAccessToken(ctx, req, ar, resp)
}

Expand Down
2 changes: 2 additions & 0 deletions handler/oidc/explicit/explicit_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@ func (c *OpenIDConnectExplicitHandler) HandleAuthorizeEndpointRequest(ctx contex
return errors.Wrap(ErrServerError, err.Error())
}

// there is no need to check for https, because it has already been checked by core.explicit

return nil
}
3 changes: 3 additions & 0 deletions handler/oidc/hybrid/hybrid.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ func (c *OpenIDConnectHybridHandler) HandleAuthorizeEndpointRequest(ctx context.
return errors.Wrap(err, err.Error())
}

// there is no need to check for https, because implicit flow does not require https
// https://tools.ietf.org/html/rfc6819#section-4.4.2

ar.SetResponseTypeHandled("id_token")
return nil
}
3 changes: 3 additions & 0 deletions handler/oidc/implicit/implicit.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ func (c *OpenIDConnectImplicitHandler) HandleAuthorizeEndpointRequest(ctx contex
return errors.Wrap(err, err.Error())
}

// there is no need to check for https, because implicit flow does not require https
// https://tools.ietf.org/html/rfc6819#section-4.4.2

ar.SetResponseTypeHandled("id_token")
return nil
}

0 comments on commit 6c40c08

Please sign in to comment.