// LogIntoGoogle runs the Log into Google action. func (c *AuthenticationController) LogIntoGoogle(ctx *app.LogIntoGoogleAuthenticationContext) error { w := goa.Response(ctx).ResponseWriter r := goa.Request(ctx).Request url := googleOauthConfig.AuthCodeURL(oauthStateString) http.Redirect(w, r, url, http.StatusTemporaryRedirect) return nil }
// CallbackResponseFromGoogle runs the Callback response from Google action. func (c *AuthenticationController) CallbackResponseFromGoogle(ctx *app.CallbackResponseFromGoogleAuthenticationContext) error { w := goa.Response(ctx).ResponseWriter r := goa.Request(ctx).Request code := r.FormValue("code") state := r.FormValue("state") fmt.Fprintf(w, "Hello! Code is: %s\n", code) if state != oauthStateString { fmt.Printf("invalid oauth state, expected '%s', got '%s'\n", oauthStateString, state) http.Redirect(w, r, "/", http.StatusTemporaryRedirect) return nil } token, err := googleOauthConfig.Exchange(oauth2.NoContext, code) if err != nil { fmt.Println("Code exchange failed with:", err) http.Redirect(w, r, "/", http.StatusTemporaryRedirect) return nil } response, err := http.Get("https://www.googleapis.com/oauth2/v2/userinfo?access_token=" + token.AccessToken) defer response.Body.Close() contents, err := ioutil.ReadAll(response.Body) if err != nil { fmt.Println("Issue parsing response body:", err) return nil } fmt.Fprintf(w, "{Content: %s, AuthToken: %s}", contents, token.AccessToken) return nil }
// LogIntoGithub runs the Log into Github action. func (c *AuthenticationController) LogIntoGithub(ctx *app.LogIntoGithubAuthenticationContext) error { w := goa.Response(ctx).ResponseWriter r := goa.Request(ctx).Request url := github.Endpoint.AuthURL http.Redirect(w, r, url, http.StatusTemporaryRedirect) return nil }
// CallbackResponseFromGithub runs the Callback response from Google action. func (c *AuthenticationController) CallbackResponseFromGithub(ctx *app.CallbackResponseFromGithubAuthenticationContext) error { w := goa.Response(ctx).ResponseWriter r := goa.Request(ctx).Request code := r.FormValue("code") state := r.FormValue("state") fmt.Fprintf(w, "Hello! Code is: %s", code) if state != oauthStateString { fmt.Printf("invalid oauth state, expected '%s', got '%s'\n", oauthStateString, state) http.Redirect(w, r, "/", http.StatusTemporaryRedirect) return nil } return nil }
// LogIntoFacebook runs the Log into Google action. func (c *AuthenticationController) LogIntoFacebook(ctx *app.LogIntoFacebookAuthenticationContext) error { w := goa.Response(ctx).ResponseWriter r := goa.Request(ctx).Request fbRedirectURL := &url.URL{ Scheme: "http", Path: facebook.Endpoint.AuthURL, } queries := fbRedirectURL.Query() queries.Set("app_id", facebookOauthConfig.ClientID) queries.Set("redirect_uri", facebookOauthConfig.RedirectURL) queries.Set("state", oauthStateString) fbRedirectURL.RawQuery = queries.Encode() goa.Info(ctx, "redirect", goa.KV{Key: "EscapedPath", Value: fbRedirectURL.RequestURI()}) http.Redirect(w, r, fbRedirectURL.RequestURI(), http.StatusTemporaryRedirect) return nil }
// CallbackResponseFromFacebook runs the Callback response from Facebook action. func (c *AuthenticationController) CallbackResponseFromFacebook(ctx *app.CallbackResponseFromFacebookAuthenticationContext) error { w := goa.Response(ctx).ResponseWriter r := goa.Request(ctx).Request code := r.FormValue("code") state := r.FormValue("state") // fmt.Fprintf(w, "Hello! Code is: %s", code) if state != oauthStateString { fmt.Printf("invalid oauth state, expected '%s', got '%s'\n", oauthStateString, state) http.Redirect(w, r, "/", http.StatusTemporaryRedirect) return nil } token, err := facebookOauthConfig.Exchange(oauth2.NoContext, code) if err != nil { fmt.Println("Code exchange failed with:", err) http.Redirect(w, r, "/", http.StatusTemporaryRedirect) return nil } fbTokenURL := &url.URL{ Scheme: "http", Path: facebook.Endpoint.AuthURL, } queries := fbTokenURL.Query() queries.Set("client_id", facebookOauthConfig.ClientID) queries.Set("redirect_uri", facebookOauthConfig.RedirectURL) queries.Set("client_secret", secrets.Facebook.Secret) queries.Set("code", code) fbTokenURL.RawQuery = queries.Encode() response, err := http.Get(fbTokenURL.RequestURI()) if err != nil { return err } defer response.Body.Close() goa.Info(ctx, "token received", goa.KV{Key: "AccessToken", Value: token.AccessToken}) return nil }
// NewMultiplyOperandsContext parses the incoming request URL and body, performs validations and creates the // context used by the operands controller multiply action. func NewMultiplyOperandsContext(ctx context.Context) (*MultiplyOperandsContext, error) { var err error req := goa.Request(ctx) rctx := MultiplyOperandsContext{Context: ctx, ResponseData: goa.Response(ctx), RequestData: req} rawLeft := req.Params.Get("left") if rawLeft != "" { if left, err2 := strconv.Atoi(rawLeft); err2 == nil { rctx.Left = left } else { err = goa.InvalidParamTypeError("left", rawLeft, "integer", err) } } rawRight := req.Params.Get("right") if rawRight != "" { if right, err2 := strconv.Atoi(rawRight); err2 == nil { rctx.Right = right } else { err = goa.InvalidParamTypeError("right", rawRight, "integer", err) } } return &rctx, err }
// NewCallbackResponseFromGoogleAuthenticationContext parses the incoming request URL and body, performs validations and creates the // context used by the authentication controller Callback response from Google action. func NewCallbackResponseFromGoogleAuthenticationContext(ctx context.Context) (*CallbackResponseFromGoogleAuthenticationContext, error) { var err error req := goa.Request(ctx) rctx := CallbackResponseFromGoogleAuthenticationContext{Context: ctx, ResponseData: goa.Response(ctx), RequestData: req} return &rctx, err }
// NewLogIntoGoogleAuthenticationContext parses the incoming request URL and body, performs validations and creates the // context used by the authentication controller Log into Google action. func NewLogIntoGoogleAuthenticationContext(ctx context.Context) (*LogIntoGoogleAuthenticationContext, error) { var err error req := goa.Request(ctx) rctx := LogIntoGoogleAuthenticationContext{Context: ctx, ResponseData: goa.Response(ctx), RequestData: req} return &rctx, err }
}) BeforeEach(func() { handler = func(c context.Context, rw http.ResponseWriter, req *http.Request) error { ctx = c rw.WriteHeader(respStatus) rw.Write(respContent) return nil } unmarshaler = func(c context.Context, req *http.Request) error { ctx = c if req != nil { var payload interface{} err := goa.RequestService(ctx).DecodeRequest(req, &payload) Ω(err).ShouldNot(HaveOccurred()) goa.Request(ctx).Payload = payload } return nil } }) It("creates a handle", func() { Ω(muxHandler).ShouldNot(BeNil()) }) Context("with a request", func() { var rw http.ResponseWriter var r *http.Request var p url.Values BeforeEach(func() {