auth
auth/info.go
Continue our descent to horribleness. Remove all the nonsense about "extensibility" and "clean separation of concerns", instead hardcoding connections to decisions. Remove all those "test" things that stopped passing.
1.1 --- a/info.go Fri Jul 18 07:13:22 2014 -0400 1.2 +++ b/info.go Fri Aug 01 23:08:38 2014 -0400 1.3 @@ -1,59 +1,37 @@ 1.4 package oauth2 1.5 1.6 -import "net/http" 1.7 - 1.8 -// InfoRequest is a request for information about some AccessData 1.9 -type InfoRequest struct { 1.10 - Code string // Code to look up 1.11 - AccessData AccessData // AccessData associated with Code 1.12 -} 1.13 +import ( 1.14 + "net/http" 1.15 + "time" 1.16 +) 1.17 1.18 // HandleInfoRequest is an http.HandlerFunc for server information 1.19 // NOT an RFC specification. 1.20 func HandleInfoRequest(w http.ResponseWriter, r *http.Request, ctx Context) { 1.21 r.ParseForm() 1.22 1.23 - // generate info request 1.24 - ret := InfoRequest{ 1.25 - Code: r.Form.Get("code"), 1.26 - } 1.27 + code := r.Form.Get("code") 1.28 1.29 - if ret.Code == "" { 1.30 + if code == "" { 1.31 // TODO: return error 1.32 return 1.33 } 1.34 1.35 - var err error 1.36 - 1.37 // load access data 1.38 - ret.AccessData, err = loadAccess(ret.Code, ctx) 1.39 + accessData, err := ctx.Tokens.GetAccess(code) 1.40 if err != nil { 1.41 // TODO: return error 1.42 return 1.43 } 1.44 - if ret.AccessData.Client.RedirectURI == "" { 1.45 + if accessData.Client.RedirectURI == "" { 1.46 // TODO: return error 1.47 return 1.48 } 1.49 - if ret.AccessData.IsExpired() { 1.50 + if accessData.IsExpired() { 1.51 // TODO: return error 1.52 return 1.53 } 1.54 - // TODO: write ret 1.55 + 1.56 + accessData.ExpiresIn = int32(accessData.CreatedAt.Add(time.Duration(accessData.ExpiresIn)*time.Second).Sub(time.Now()) / time.Second) 1.57 + // TODO: write accessData 1.58 } 1.59 - 1.60 -// FinishInfoRequest finalizes the request handled by HandleInfoRequest 1.61 -func FinishInfoRequest(w http.ResponseWriter, r *http.Request, ir *InfoRequest, ctx Context) { 1.62 - // output data 1.63 - //w.Output["client_id"] = ir.AccessData.Client.Id 1.64 - //w.Output["access_token"] = ir.AccessData.AccessToken 1.65 - //w.Output["token_type"] = s.Config.TokenType 1.66 - //w.Output["expires_in"] = ir.AccessData.CreatedAt.Add(time.Duration(ir.AccessData.ExpiresIn)*time.Second).Sub(time.Now()) / time.Second 1.67 - //if ir.AccessData.RefreshToken != "" { 1.68 - // w.Output["refresh_token"] = ir.AccessData.RefreshToken 1.69 - //} 1.70 - //if ir.AccessData.Scope != "" { 1.71 - // w.Output["scope"] = ir.AccessData.Scope 1.72 - //} 1.73 - // TODO: write output 1.74 -}