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

refactoring #1190

Merged
merged 2 commits into from
Nov 29, 2018
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
7 changes: 1 addition & 6 deletions client/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,7 @@ const (
ClientsHandlerPath = "/clients"
)

func NewHandler(
manager Manager,
h herodot.Writer,
defaultClientScopes []string,
subjectTypes []string,
) *Handler {
func NewHandler(manager Manager, h herodot.Writer, defaultClientScopes, subjectTypes []string) *Handler {
return &Handler{
Manager: manager,
H: h,
Expand Down
5 changes: 1 addition & 4 deletions client/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ type Validator struct {
SubjectTypes []string
}

func NewValidator(
defaultClientScopes []string,
subjectTypes []string,
) *Validator {
func NewValidator(defaultClientScopes, subjectTypes []string) *Validator {
if len(subjectTypes) == 0 {
subjectTypes = []string{"public"}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/handler_jwk.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (h *JWKHandler) CreateKeys(cmd *cobra.Command, args []string) {
fmt.Println(formatResponse(keys))
}

func toSDKFriendlyJSONWebKey(key interface{}, kid string, use string, public bool) jose.JSONWebKey {
func toSDKFriendlyJSONWebKey(key interface{}, kid, use string, public bool) jose.JSONWebKey {
if jwk, ok := key.(*jose.JSONWebKey); ok {
key = jwk.Key
if jwk.KeyID != "" {
Expand Down
8 changes: 4 additions & 4 deletions cmd/server/handler_oauth2_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func newOAuth2Provider(c *config.Config) fosite.OAuth2Provider {
)
}

func setDefaultConsentURL(s string, c *config.Config, path string) string {
func setDefaultConsentURL(c *config.Config, s, path string) string {
if s != "" {
return s
}
Expand All @@ -168,9 +168,9 @@ func setDefaultConsentURL(s string, c *config.Config, path string) string {
func newOAuth2Handler(c *config.Config, frontend, backend *httprouter.Router, cm consent.Manager, o fosite.OAuth2Provider, clm client.Manager) *oauth2.Handler {
expectDependency(c.GetLogger(), c.Context().FositeStore, clm)

c.ConsentURL = setDefaultConsentURL(c.ConsentURL, c, "oauth2/fallbacks/consent")
c.LoginURL = setDefaultConsentURL(c.LoginURL, c, "oauth2/fallbacks/consent")
c.ErrorURL = setDefaultConsentURL(c.ErrorURL, c, "oauth2/fallbacks/error")
c.ConsentURL = setDefaultConsentURL(c, c.ConsentURL, "oauth2/fallbacks/consent")
c.LoginURL = setDefaultConsentURL(c, c.LoginURL, "oauth2/fallbacks/consent")
c.ErrorURL = setDefaultConsentURL(c, c.ErrorURL, "oauth2/fallbacks/error")

errorURL, err := url.Parse(c.ErrorURL)
cmdx.Must(err, "Could not parse error url %s.", errorURL)
Expand Down
2 changes: 1 addition & 1 deletion cmd/server/helper_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"github.com/ory/hydra/pkg"
)

func createOrGetJWK(c *config.Config, set string, kid string, prefix string) (key *jose.JSONWebKey, err error) {
func createOrGetJWK(c *config.Config, set, kid, prefix string) (key *jose.JSONWebKey, err error) {
ctx := c.Context()

expectDependency(c.GetLogger(), ctx.KeyManager)
Expand Down
2 changes: 1 addition & 1 deletion consent/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type Manager interface {
RevokeUserClientConsentSession(ctx context.Context, user, client string) error

VerifyAndInvalidateConsentRequest(ctx context.Context, verifier string) (*HandledConsentRequest, error)
FindPreviouslyGrantedConsentRequests(ctx context.Context, client string, user string) ([]HandledConsentRequest, error)
FindPreviouslyGrantedConsentRequests(ctx context.Context, client, user string) ([]HandledConsentRequest, error)
FindPreviouslyGrantedConsentRequestsByUser(ctx context.Context, user string, limit, offset int) ([]HandledConsentRequest, error)

// Cookie management
Expand Down
2 changes: 1 addition & 1 deletion consent/manager_memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func (m *MemoryManager) VerifyAndInvalidateConsentRequest(ctx context.Context, v
return nil, errors.WithStack(pkg.ErrNotFound)
}

func (m *MemoryManager) FindPreviouslyGrantedConsentRequests(ctx context.Context, client string, subject string) ([]HandledConsentRequest, error) {
func (m *MemoryManager) FindPreviouslyGrantedConsentRequests(ctx context.Context, client, subject string) ([]HandledConsentRequest, error) {
var rs []HandledConsentRequest
filteredByUser, err := m.FindPreviouslyGrantedConsentRequestsByUser(ctx, subject, -1, -1)
if errors.Cause(err) == pkg.ErrNotFound {
Expand Down
2 changes: 1 addition & 1 deletion consent/manager_sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ func (m *SQLManager) DeleteAuthenticationSession(ctx context.Context, id string)
return nil
}

func (m *SQLManager) FindPreviouslyGrantedConsentRequests(ctx context.Context, client string, subject string) ([]HandledConsentRequest, error) {
func (m *SQLManager) FindPreviouslyGrantedConsentRequests(ctx context.Context, client, subject string) ([]HandledConsentRequest, error) {
var a []sqlHandledConsentRequest

if err := m.DB.SelectContext(ctx, &a, m.DB.Rebind(`SELECT h.* FROM
Expand Down
8 changes: 4 additions & 4 deletions consent/strategy_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (s *DefaultStrategy) requestAuthentication(w http.ResponseWriter, r *http.R
return errors.WithStack(fosite.ErrInvalidRequest.WithDebug("Failed to validate OpenID Connect request as decoding id token from id_token_hint to *jwt.StandardClaims failed"))
} else if hintSub, _ := hintClaims["sub"].(string); hintSub == "" {
return errors.WithStack(fosite.ErrInvalidRequest.WithDebug("Failed to validate OpenID Connect request because provided id token from id_token_hint does not have a subject"))
} else if obfuscatedUserID, err = s.obfuscateSubjectIdentifier(session.Subject, ar, ""); err != nil {
} else if obfuscatedUserID, err = s.obfuscateSubjectIdentifier(ar, session.Subject, ""); err != nil {
return err
}

Expand Down Expand Up @@ -294,7 +294,7 @@ func revokeAuthenticationCookie(w http.ResponseWriter, r *http.Request, s sessio
return sid, nil
}

func (s *DefaultStrategy) obfuscateSubjectIdentifier(subject string, req fosite.AuthorizeRequester, forcedIdentifier string) (string, error) {
func (s *DefaultStrategy) obfuscateSubjectIdentifier(req fosite.AuthorizeRequester, subject, forcedIdentifier string) (string, error) {
if c, ok := req.GetClient().(*client.Client); ok && c.SubjectType == "pairwise" {
algorithm, ok := s.SubjectIdentifierAlgorithm[c.SubjectType]
if !ok {
Expand Down Expand Up @@ -346,7 +346,7 @@ func (s *DefaultStrategy) verifyAuthentication(w http.ResponseWriter, r *http.Re
return nil, errors.WithStack(fosite.ErrServerError.WithDebug("The login request is marked as remember, but the subject from the login confirmation does not match the original subject from the cookie."))
}

subjectIdentifier, err := s.obfuscateSubjectIdentifier(session.Subject, req, session.ForceSubjectIdentifier)
subjectIdentifier, err := s.obfuscateSubjectIdentifier(req, session.Subject, session.ForceSubjectIdentifier)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -572,7 +572,7 @@ func (s *DefaultStrategy) verifyConsent(w http.ResponseWriter, r *http.Request,
return nil, err
}

pw, err := s.obfuscateSubjectIdentifier(session.ConsentRequest.Subject, req, session.ConsentRequest.ForceSubjectIdentifier)
pw, err := s.obfuscateSubjectIdentifier(req, session.ConsentRequest.Subject, session.ConsentRequest.ForceSubjectIdentifier)
if err != nil {
return nil, err
}
Expand Down