fix: rename server_url -> authorizer_domain

This commit is contained in:
Lakhan Samani
2021-07-28 16:38:55 +05:30
parent 030cf9eeee
commit 464f9105c4
9 changed files with 36 additions and 41 deletions

View File

@@ -163,14 +163,17 @@ func processGithubUserInfo(state string, code string, c *gin.Context) error {
return nil
}
func OAuthCallbackHandler(provider enum.OAuthProvider) gin.HandlerFunc {
func OAuthCallbackHandler() gin.HandlerFunc {
return func(c *gin.Context) {
provider := c.Param("oauth_provider")
var err error
if provider == enum.GoogleProvider {
switch provider {
case enum.Google.String():
err = processGoogleUserInfo(c.Request.FormValue("state"), c.Request.FormValue("code"), c)
}
if provider == enum.GithubProvider {
case enum.Github.String():
err = processGithubUserInfo(c.Request.FormValue("state"), c.Request.FormValue("code"), c)
default:
err = fmt.Errorf(`invalid oauth provider`)
}
if err != nil {

View File

@@ -10,20 +10,26 @@ import (
"github.com/google/uuid"
)
func OAuthLoginHandler(provider enum.OAuthProvider) gin.HandlerFunc {
func OAuthLoginHandler() gin.HandlerFunc {
uuid := uuid.New()
oauthStateString := uuid.String()
return func(c *gin.Context) {
if provider == enum.GoogleProvider {
provider := c.Param("oauth_provider")
switch provider {
case enum.Google.String():
session.SetToken(oauthStateString, enum.Google.String())
url := oauth.OAuthProvider.GoogleConfig.AuthCodeURL(oauthStateString)
c.Redirect(http.StatusTemporaryRedirect, url)
}
if provider == enum.GithubProvider {
case enum.Github.String():
session.SetToken(oauthStateString, enum.Github.String())
url := oauth.OAuthProvider.GithubConfig.AuthCodeURL(oauthStateString)
c.Redirect(http.StatusTemporaryRedirect, url)
default:
c.JSON(422, gin.H{
"message": "Invalid oauth provider",
})
}
}
}