-
Notifications
You must be signed in to change notification settings - Fork 157
/
oauth_start.go
32 lines (24 loc) · 1.11 KB
/
oauth_start.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package githubapp
import (
"github.com/labstack/echo/v4"
"golang.org/x/oauth2"
"github.com/hatchet-dev/hatchet/api/v1/server/authn"
"github.com/hatchet-dev/hatchet/api/v1/server/oas/gen"
)
// Note: we want all errors to redirect, otherwise the user will be greeted with raw JSON in the middle of the login flow.
func (g *GithubAppService) UserUpdateGithubAppOauthStart(ctx echo.Context, _ gen.UserUpdateGithubAppOauthStartRequestObject) (gen.UserUpdateGithubAppOauthStartResponseObject, error) {
ghApp, err := GetGithubAppConfig(g.config)
if err != nil {
return nil, authn.GetRedirectWithError(ctx, g.config.Logger, err, "Github app is misconfigured on this Hatchet instance.")
}
state, err := authn.NewSessionHelpers(g.config).SaveOAuthState(ctx, "github")
if err != nil {
return nil, authn.GetRedirectWithError(ctx, g.config.Logger, err, "Could not get cookie. Please make sure cookies are enabled.")
}
url := ghApp.AuthCodeURL(state, oauth2.AccessTypeOffline)
return gen.UserUpdateGithubAppOauthStart302Response{
Headers: gen.UserUpdateGithubAppOauthStart302ResponseHeaders{
Location: url,
},
}, nil
}