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.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/info.go	Fri Jul 18 07:13:22 2014 -0400
     1.3 @@ -0,0 +1,59 @@
     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 +
    1.14 +// HandleInfoRequest is an http.HandlerFunc for server information
    1.15 +// NOT an RFC specification.
    1.16 +func HandleInfoRequest(w http.ResponseWriter, r *http.Request, ctx Context) {
    1.17 +	r.ParseForm()
    1.18 +
    1.19 +	// generate info request
    1.20 +	ret := InfoRequest{
    1.21 +		Code: r.Form.Get("code"),
    1.22 +	}
    1.23 +
    1.24 +	if ret.Code == "" {
    1.25 +		// TODO: return error
    1.26 +		return
    1.27 +	}
    1.28 +
    1.29 +	var err error
    1.30 +
    1.31 +	// load access data
    1.32 +	ret.AccessData, err = loadAccess(ret.Code, ctx)
    1.33 +	if err != nil {
    1.34 +		// TODO: return error
    1.35 +		return
    1.36 +	}
    1.37 +	if ret.AccessData.Client.RedirectURI == "" {
    1.38 +		// TODO: return error
    1.39 +		return
    1.40 +	}
    1.41 +	if ret.AccessData.IsExpired() {
    1.42 +		// TODO: return error
    1.43 +		return
    1.44 +	}
    1.45 +	// TODO: write ret
    1.46 +}
    1.47 +
    1.48 +// FinishInfoRequest finalizes the request handled by HandleInfoRequest
    1.49 +func FinishInfoRequest(w http.ResponseWriter, r *http.Request, ir *InfoRequest, ctx Context) {
    1.50 +	// output data
    1.51 +	//w.Output["client_id"] = ir.AccessData.Client.Id
    1.52 +	//w.Output["access_token"] = ir.AccessData.AccessToken
    1.53 +	//w.Output["token_type"] = s.Config.TokenType
    1.54 +	//w.Output["expires_in"] = ir.AccessData.CreatedAt.Add(time.Duration(ir.AccessData.ExpiresIn)*time.Second).Sub(time.Now()) / time.Second
    1.55 +	//if ir.AccessData.RefreshToken != "" {
    1.56 +	//	w.Output["refresh_token"] = ir.AccessData.RefreshToken
    1.57 +	//}
    1.58 +	//if ir.AccessData.Scope != "" {
    1.59 +	//	w.Output["scope"] = ir.AccessData.Scope
    1.60 +	//}
    1.61 +	// TODO: write output
    1.62 +}