auth

Paddy 2014-08-13 Parent:65c49af1ed3f Child:7ae3f16002c1

4:422e9082eb70 Browse Files

Write responses. Start writing JSON responses when access tokens are requested.

access.go context.go

     1.1 --- a/access.go	Sun Aug 03 02:06:50 2014 -0400
     1.2 +++ b/access.go	Wed Aug 13 03:45:24 2014 -0400
     1.3 @@ -140,7 +140,7 @@
     1.4  		// TODO: return error
     1.5  		return
     1.6  	}
     1.7 -	// TODO: write data
     1.8 +	ctx.RenderJSONToken(w, data)
     1.9  }
    1.10  
    1.11  func handleRefreshTokenRequest(w http.ResponseWriter, r *http.Request, ctx Context) {
    1.12 @@ -209,14 +209,14 @@
    1.13  		// TODO: return error
    1.14  		return
    1.15  	}
    1.16 -	// TODO: write data
    1.17 +	ctx.RenderJSONToken(w, data)
    1.18  }
    1.19  
    1.20  func handlePasswordRequest(w http.ResponseWriter, r *http.Request, ctx Context) {
    1.21  	// get client authentication
    1.22  	auth, err := getClientAuth(r, ctx.Config.AllowClientSecretInParams)
    1.23  	if err != nil {
    1.24 -		// TODO: return error
    1.25 +		ctx.RenderJSONError(w, ErrorInvalidClient, "Invalid client auth.", ctx.Config.DocumentationDomain)
    1.26  		return
    1.27  	}
    1.28  
    1.29 @@ -226,7 +226,7 @@
    1.30  
    1.31  	// "username" and "password" is required
    1.32  	if username == "" || password == "" {
    1.33 -		// TODO: return error
    1.34 +		ctx.RenderJSONError(w, ErrorInvalidRequest, "Missing credentials.", ctx.Config.DocumentationDomain)
    1.35  		return
    1.36  	}
    1.37  
    1.38 @@ -262,15 +262,14 @@
    1.39  		// TODO: return error
    1.40  		return
    1.41  	}
    1.42 -
    1.43 -	// TODO: write data
    1.44 +	ctx.RenderJSONToken(w, data)
    1.45  }
    1.46  
    1.47  func handleClientCredentialsRequest(w http.ResponseWriter, r *http.Request, ctx Context) {
    1.48  	// get client authentication
    1.49  	auth, err := getClientAuth(r, ctx.Config.AllowClientSecretInParams)
    1.50  	if err != nil {
    1.51 -		// TODO: return error
    1.52 +		ctx.RenderJSONError(w, ErrorInvalidClient, "Invalid client auth.", ctx.Config.DocumentationDomain)
    1.53  		return
    1.54  	}
    1.55  
    1.56 @@ -302,8 +301,7 @@
    1.57  		// TODO: return error
    1.58  		return
    1.59  	}
    1.60 -
    1.61 -	// TODO: write data
    1.62 +	ctx.RenderJSONToken(w, data)
    1.63  }
    1.64  
    1.65  func fillTokens(data *AccessData, includeRefresh bool, ctx Context) error {
     2.1 --- a/context.go	Sun Aug 03 02:06:50 2014 -0400
     2.2 +++ b/context.go	Wed Aug 13 03:45:24 2014 -0400
     2.3 @@ -20,3 +20,6 @@
     2.4  
     2.5  func (c Context) RenderLogin(w io.Writer) {
     2.6  }
     2.7 +
     2.8 +func (c Context) RenderJSONToken(w io.Writer, data AccessData) {
     2.9 +}