auth

Paddy 2014-07-18 Child:7b9e0fc20256

0:7a6f64db7246 Go to Latest

auth/info.go

Start rewriting the repo. This code originally was a carbon copy of https://github.com/RangelReale/osin, but I am methodically stripping out the extensible nature of it for a simpler interface, while simultaneously bringing the style into line with the Ducky style.

History
1 package oauth2
3 import "net/http"
5 // InfoRequest is a request for information about some AccessData
6 type InfoRequest struct {
7 Code string // Code to look up
8 AccessData AccessData // AccessData associated with Code
9 }
11 // HandleInfoRequest is an http.HandlerFunc for server information
12 // NOT an RFC specification.
13 func HandleInfoRequest(w http.ResponseWriter, r *http.Request, ctx Context) {
14 r.ParseForm()
16 // generate info request
17 ret := InfoRequest{
18 Code: r.Form.Get("code"),
19 }
21 if ret.Code == "" {
22 // TODO: return error
23 return
24 }
26 var err error
28 // load access data
29 ret.AccessData, err = loadAccess(ret.Code, ctx)
30 if err != nil {
31 // TODO: return error
32 return
33 }
34 if ret.AccessData.Client.RedirectURI == "" {
35 // TODO: return error
36 return
37 }
38 if ret.AccessData.IsExpired() {
39 // TODO: return error
40 return
41 }
42 // TODO: write ret
43 }
45 // FinishInfoRequest finalizes the request handled by HandleInfoRequest
46 func FinishInfoRequest(w http.ResponseWriter, r *http.Request, ir *InfoRequest, ctx Context) {
47 // output data
48 //w.Output["client_id"] = ir.AccessData.Client.Id
49 //w.Output["access_token"] = ir.AccessData.AccessToken
50 //w.Output["token_type"] = s.Config.TokenType
51 //w.Output["expires_in"] = ir.AccessData.CreatedAt.Add(time.Duration(ir.AccessData.ExpiresIn)*time.Second).Sub(time.Now()) / time.Second
52 //if ir.AccessData.RefreshToken != "" {
53 // w.Output["refresh_token"] = ir.AccessData.RefreshToken
54 //}
55 //if ir.AccessData.Scope != "" {
56 // w.Output["scope"] = ir.AccessData.Scope
57 //}
58 // TODO: write output
59 }