11package api
22
33import (
4- "net/http"
54 "net/url"
65
76 "github.com/anduintransaction/oauth-proxy/provider"
@@ -15,40 +14,40 @@ import (
1514func Callback (ctx * goru.Context ) {
1615 stateName := gorux .Query (ctx , "state" )
1716 if stateName == "" {
18- gorux . ResponseJSON (ctx , http . StatusBadRequest , Error ( "state is required") )
17+ RenderError (ctx , "State is required" )
1918 return
2019 }
2120 state := proxy .GetState (stateName )
2221 if state == nil {
23- gorux . ResponseJSON (ctx , http . StatusUnauthorized , Error ( "state not found or expired") )
22+ RenderError (ctx , "State not found or expired" )
2423 return
2524 }
2625 prov := provider .GetProvider (state .Proxy .Provider )
2726 if prov == nil {
2827 log .Errorf ("Provider not found: %s" , state .Proxy .Provider )
29- gorux . ResponseJSON (ctx , http . StatusInternalServerError , InternalServerError )
28+ RenderError (ctx , InternalServerError . Message )
3029 return
3130 }
3231 code := gorux .Query (ctx , "code" )
3332 if code == "" {
3433 log .Errorf ("Error found in callback: %s" , ctx .Request .URL .String ())
35- gorux . ResponseJSON (ctx , http . StatusBadRequest , Error ( prov .ErrorString (ctx .Request ) ))
34+ RenderError (ctx , prov .ErrorString (ctx .Request ))
3635 return
3736 }
3837 token , err := prov .RequestToken (state , code )
3938 if err != nil {
4039 log .Error (err )
41- gorux . ResponseJSON (ctx , http . StatusInternalServerError , Error ( "cannot request token") )
40+ RenderError (ctx , "Cannot request token" )
4241 return
4342 }
4443 user , err := prov .VerifyUser (state , token )
4544 if err != nil {
4645 log .Error (err )
47- gorux . ResponseJSON (ctx , http . StatusInternalServerError , Error ( "cannot verify user") )
46+ RenderError (ctx , "Cannot verify user" )
4847 return
4948 }
5049 if user == nil {
51- gorux . ResponseJSON (ctx , http . StatusUnauthorized , Error ( "unauthorized user") )
50+ RenderError (ctx , "Unauthorized user" )
5251 return
5352 }
5453
0 commit comments