auth

Paddy 2014-08-03 Parent:7b9e0fc20256 Child:3423c552e249

3:65c49af1ed3f Go to Latest

auth/info.go

Render JSON errors. Start rendering JSON errors when obtaining an access token doesn't succeed.

History
1 package oauth2
3 import (
4 "net/http"
5 "time"
6 )
8 // HandleInfoRequest is an http.HandlerFunc for server information
9 // NOT an RFC specification.
10 func HandleInfoRequest(w http.ResponseWriter, r *http.Request, ctx Context) {
11 r.ParseForm()
13 code := r.Form.Get("code")
15 if code == "" {
16 // TODO: return error
17 return
18 }
20 // load access data
21 accessData, err := ctx.Tokens.GetAccess(code)
22 if err != nil {
23 // TODO: return error
24 return
25 }
26 if accessData.Client.RedirectURI == "" {
27 // TODO: return error
28 return
29 }
30 if accessData.IsExpired() {
31 // TODO: return error
32 return
33 }
35 accessData.ExpiresIn = int32(accessData.CreatedAt.Add(time.Duration(accessData.ExpiresIn)*time.Second).Sub(time.Now()) / time.Second)
36 // TODO: write accessData
37 }