diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index a055df048eb2..e61da046d0aa 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -406,7 +406,7 @@ }, { "ImportPath": "github.com/RangelReale/osin", - "Rev": "1f4e9754a8931fbd9834ab11592f358418efc9ff" + "Rev": "a9958a122a90a3b069389d394284283c19d58913" }, { "ImportPath": "github.com/RangelReale/osincli", diff --git a/Godeps/_workspace/src/github.com/RangelReale/osin/access.go b/Godeps/_workspace/src/github.com/RangelReale/osin/access.go index 40075f545fc0..e6a05fd90ab2 100644 --- a/Godeps/_workspace/src/github.com/RangelReale/osin/access.go +++ b/Godeps/_workspace/src/github.com/RangelReale/osin/access.go @@ -86,7 +86,12 @@ type AccessData struct { // IsExpired returns true if access expired func (d *AccessData) IsExpired() bool { - return d.CreatedAt.Add(time.Duration(d.ExpiresIn) * time.Second).Before(time.Now()) + return d.IsExpiredAt(time.Now()) +} + +// IsExpiredAt returns true if access expires at time 't' +func (d *AccessData) IsExpiredAt(t time.Time) bool { + return d.ExpireAt().Before(t) } // ExpireAt returns the expiration date @@ -189,7 +194,7 @@ func (s *Server) handleAuthorizationCodeRequest(w *Response, r *http.Request) *A w.SetError(E_UNAUTHORIZED_CLIENT, "") return nil } - if ret.AuthorizeData.IsExpired() { + if ret.AuthorizeData.IsExpiredAt(s.Now()) { w.SetError(E_INVALID_GRANT, "") return nil } @@ -335,7 +340,7 @@ func (s *Server) handleClientCredentialsRequest(w *Response, r *http.Request) *A ret := &AccessRequest{ Type: CLIENT_CREDENTIALS, Scope: r.Form.Get("scope"), - GenerateRefresh: true, + GenerateRefresh: false, Expiration: s.Config.AccessExpiration, HttpRequest: r, } @@ -407,7 +412,7 @@ func (s *Server) FinishAccessRequest(w *Response, r *http.Request, ar *AccessReq AuthorizeData: ar.AuthorizeData, AccessData: ar.AccessData, RedirectUri: redirectUri, - CreatedAt: time.Now(), + CreatedAt: s.Now(), ExpiresIn: ar.Expiration, UserData: ar.UserData, Scope: ar.Scope, diff --git a/Godeps/_workspace/src/github.com/RangelReale/osin/access_test.go b/Godeps/_workspace/src/github.com/RangelReale/osin/access_test.go index 1e5bb67b085b..ab6ea1eefcf8 100644 --- a/Godeps/_workspace/src/github.com/RangelReale/osin/access_test.go +++ b/Godeps/_workspace/src/github.com/RangelReale/osin/access_test.go @@ -189,7 +189,7 @@ func TestAccessClientCredentials(t *testing.T) { t.Fatalf("Unexpected access token: %s", d) } - if d := resp.Output["refresh_token"]; d != "r1" { - t.Fatalf("Unexpected refresh token: %s", d) + if d, dok := resp.Output["refresh_token"]; dok { + t.Fatalf("Refresh token should not be generated: %s", d) } } diff --git a/Godeps/_workspace/src/github.com/RangelReale/osin/authorize.go b/Godeps/_workspace/src/github.com/RangelReale/osin/authorize.go index 1f572ebfc57d..7d9dad33dd74 100644 --- a/Godeps/_workspace/src/github.com/RangelReale/osin/authorize.go +++ b/Godeps/_workspace/src/github.com/RangelReale/osin/authorize.go @@ -65,7 +65,12 @@ type AuthorizeData struct { // IsExpired is true if authorization expired func (d *AuthorizeData) IsExpired() bool { - return d.CreatedAt.Add(time.Duration(d.ExpiresIn) * time.Second).Before(time.Now()) + return d.IsExpiredAt(time.Now()) +} + +// IsExpired is true if authorization expires at time 't' +func (d *AuthorizeData) IsExpiredAt(t time.Time) bool { + return d.ExpireAt().Before(t) } // ExpireAt returns the expiration date @@ -221,11 +226,14 @@ func (s *Server) FinishAuthorizeRequest(w *Response, r *http.Request, ar *Author } s.FinishAccessRequest(w, r, ret) + if ar.State != "" && w.InternalError == nil { + w.Output["state"] = ar.State + } } else { // generate authorization token ret := &AuthorizeData{ Client: ar.Client, - CreatedAt: time.Now(), + CreatedAt: s.Now(), ExpiresIn: ar.Expiration, RedirectUri: ar.RedirectUri, State: ar.State, diff --git a/Godeps/_workspace/src/github.com/RangelReale/osin/example/complete/complete.go b/Godeps/_workspace/src/github.com/RangelReale/osin/example/complete/complete.go index 23cc78d10eb8..f22ce9fc1d23 100644 --- a/Godeps/_workspace/src/github.com/RangelReale/osin/example/complete/complete.go +++ b/Godeps/_workspace/src/github.com/RangelReale/osin/example/complete/complete.go @@ -106,60 +106,59 @@ func main() { w.Write([]byte("
")) w.Write([]byte("APP AUTH - CODE