Skip to content

Commit

Permalink
pkg: moved package pkg to ory-am/common
Browse files Browse the repository at this point in the history
  • Loading branch information
Aeneas Rekkas committed Nov 26, 2015
1 parent 975e6c7 commit 2dd45a9
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 76 deletions.
2 changes: 1 addition & 1 deletion account/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"github.com/asaskevich/govalidator"
"github.com/gorilla/mux"
chd "github.com/ory-am/common/handler"
. "github.com/ory-am/common/pkg"
. "github.com/ory-am/hydra/account"
"github.com/ory-am/hydra/middleware"
. "github.com/ory-am/hydra/pkg"
"github.com/pborman/uuid"
"golang.org/x/net/context"
"net/http"
Expand Down
2 changes: 1 addition & 1 deletion client/http/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package http_test
import (
"github.com/RangelReale/osin"
"github.com/gorilla/mux"
"github.com/ory-am/common/pkg"
. "github.com/ory-am/hydra/client"
. "github.com/ory-am/hydra/client/http"
"github.com/ory-am/hydra/pkg"
"github.com/stretchr/testify/assert"
"golang.org/x/oauth2"
"net/http"
Expand Down
7 changes: 2 additions & 5 deletions middleware/env.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package middleware

import (
"github.com/ory-am/common/pkg"
"github.com/ory-am/ladon/guard/operator"
"net/http"
"time"
Expand All @@ -23,11 +24,7 @@ func (e *Env) Ctx() *operator.Context {
}

func (e *Env) Req(req *http.Request) *Env {
ip := req.Header.Get("X-Forwarded-For")
if ip == "" {
ip = req.RemoteAddr
}
e.ctx.ClientIP = ip
e.ctx.ClientIP = pkg.GetIP(req)
e.ctx.UserAgent = req.Header.Get("User-Agent")
e.ctx.Timestamp = time.Now()
return e
Expand Down
2 changes: 1 addition & 1 deletion oauth/client/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"github.com/asaskevich/govalidator"
"github.com/gorilla/mux"
chd "github.com/ory-am/common/handler"
. "github.com/ory-am/common/pkg"
"github.com/ory-am/common/rand/sequence"
"github.com/ory-am/hydra/middleware"
. "github.com/ory-am/hydra/pkg"
"github.com/ory-am/osin-storage/storage"
"github.com/pborman/uuid"
"golang.org/x/net/context"
Expand Down
2 changes: 1 addition & 1 deletion oauth/connection/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"github.com/asaskevich/govalidator"
"github.com/gorilla/mux"
hydcon "github.com/ory-am/common/handler"
. "github.com/ory-am/common/pkg"
"github.com/ory-am/hydra/middleware"
. "github.com/ory-am/hydra/oauth/connection"
. "github.com/ory-am/hydra/pkg"
"github.com/pborman/uuid"
"golang.org/x/net/context"
"net/http"
Expand Down
14 changes: 7 additions & 7 deletions oauth/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (
"github.com/go-errors/errors"
"github.com/gorilla/mux"
hctx "github.com/ory-am/common/handler"
"github.com/ory-am/common/pkg"
"github.com/ory-am/hydra/account"
"github.com/ory-am/hydra/jwt"
"github.com/ory-am/hydra/middleware"
"github.com/ory-am/hydra/middleware"
"github.com/ory-am/hydra/oauth/connection"
"github.com/ory-am/hydra/oauth/provider"
"github.com/ory-am/hydra/oauth/provider/storage"
Expand All @@ -22,7 +23,6 @@ import (
"net/http"
"net/url"
"time"
"github.com/ory-am/hydra/pkg"
)

func DefaultConfig() *osin.ServerConfig {
Expand Down Expand Up @@ -141,7 +141,7 @@ func (h *Handler) TokenHandler(w http.ResponseWriter, r *http.Request) {
return
}

ar.UserData = jwt.NewClaimsCarrier(uuid.New(), h.Issuer, claims.GetSubject(), h.Audience, time.Now().Add(time.Duration(ar.Expiration) * time.Second), time.Now(), time.Now())
ar.UserData = jwt.NewClaimsCarrier(uuid.New(), h.Issuer, claims.GetSubject(), h.Audience, time.Now().Add(time.Duration(ar.Expiration)*time.Second), time.Now(), time.Now())
ar.Authorized = true
case osin.REFRESH_TOKEN:
data, ok := ar.UserData.(map[string]interface{})
Expand All @@ -150,19 +150,19 @@ func (h *Handler) TokenHandler(w http.ResponseWriter, r *http.Request) {
return
}
claims := jwt.ClaimsCarrier(data)
ar.UserData = jwt.NewClaimsCarrier(uuid.New(), h.Issuer, claims.GetSubject(), h.Audience, time.Now().Add(time.Duration(ar.Expiration) * time.Second), time.Now(), time.Now())
ar.UserData = jwt.NewClaimsCarrier(uuid.New(), h.Issuer, claims.GetSubject(), h.Audience, time.Now().Add(time.Duration(ar.Expiration)*time.Second), time.Now(), time.Now())
ar.Authorized = true
case osin.PASSWORD:
// TODO if !ar.Client.isAllowedToAuthenticateUser
// TODO ... return
// TODO }

if user, err := h.authenticate(w, r, ar.Username, ar.Password); err == nil {
ar.UserData = jwt.NewClaimsCarrier(uuid.New(), h.Issuer, user.GetID(), h.Audience, time.Now().Add(time.Duration(ar.Expiration) * time.Second), time.Now(), time.Now())
ar.UserData = jwt.NewClaimsCarrier(uuid.New(), h.Issuer, user.GetID(), h.Audience, time.Now().Add(time.Duration(ar.Expiration)*time.Second), time.Now(), time.Now())
ar.Authorized = true
}
case osin.CLIENT_CREDENTIALS:
ar.UserData = jwt.NewClaimsCarrier(uuid.New(), h.Issuer, ar.Client.GetId(), h.Audience, time.Now().Add(time.Duration(ar.Expiration) * time.Second), time.Now(), time.Now())
ar.UserData = jwt.NewClaimsCarrier(uuid.New(), h.Issuer, ar.Client.GetId(), h.Audience, time.Now().Add(time.Duration(ar.Expiration)*time.Second), time.Now(), time.Now())
ar.Authorized = true

// TODO ASSERTION workflow http://leastprivilege.com/2013/12/23/advanced-oauth2-assertion-flow-why/
Expand Down Expand Up @@ -275,7 +275,7 @@ func (h *Handler) AuthorizeHandler(w http.ResponseWriter, r *http.Request) {
return
}

ar.UserData = jwt.NewClaimsCarrier(uuid.New(), user.GetLocalSubject(), h.Issuer, h.Audience, time.Now().Add(time.Duration(ar.Expiration) * time.Second), time.Now(), time.Now())
ar.UserData = jwt.NewClaimsCarrier(uuid.New(), user.GetLocalSubject(), h.Issuer, h.Audience, time.Now().Add(time.Duration(ar.Expiration)*time.Second), time.Now(), time.Now())
ar.Authorized = true
h.server.FinishAuthorizeRequest(resp, r, ar)
}
Expand Down
19 changes: 0 additions & 19 deletions pkg/writeJSON.go

This file was deleted.

40 changes: 0 additions & 40 deletions pkg/writeJSON_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion policy/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"fmt"
"github.com/gorilla/mux"
hctx "github.com/ory-am/common/handler"
"github.com/ory-am/common/pkg"
"github.com/ory-am/hydra/middleware"
"github.com/ory-am/hydra/pkg"
"github.com/pborman/uuid"
"golang.org/x/net/context"
"net/http"
Expand Down

0 comments on commit 2dd45a9

Please sign in to comment.