fix: update authorizer-react + oauth callback
This commit is contained in:
parent
b9872b5aac
commit
5c3a5000cd
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
2772
app/package-lock.json
generated
2772
app/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
|
@ -1,25 +1,25 @@
|
||||||
{
|
{
|
||||||
"name": "app",
|
"name": "app",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "esbuild src/index.tsx --bundle --minify --sourcemap --outfile=build/bundle.js"
|
"build": "esbuild src/index.tsx --bundle --minify --sourcemap --outfile=build/bundle.js"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "Lakhan Samani",
|
"author": "Lakhan Samani",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@authorizerdev/authorizer-react": "^0.1.0-beta.7",
|
"@authorizerdev/authorizer-react": "^0.1.0-beta.8",
|
||||||
"@types/react": "^17.0.15",
|
"@types/react": "^17.0.15",
|
||||||
"@types/react-dom": "^17.0.9",
|
"@types/react-dom": "^17.0.9",
|
||||||
"esbuild": "^0.12.17",
|
"esbuild": "^0.12.17",
|
||||||
"react": "^17.0.2",
|
"react": "^17.0.2",
|
||||||
"react-dom": "^17.0.2",
|
"react-dom": "^17.0.2",
|
||||||
"react-router-dom": "^5.2.0",
|
"react-router-dom": "^5.2.0",
|
||||||
"typescript": "^4.3.5"
|
"typescript": "^4.3.5"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/react-router-dom": "^5.1.8"
|
"@types/react-router-dom": "^5.1.8"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -63,7 +62,9 @@ func processGoogleUserInfo(code string, c *gin.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
user, _ = db.Mgr.SaveUser(user)
|
user, _ = db.Mgr.SaveUser(user)
|
||||||
|
user, _ = db.Mgr.GetUserByEmail(user.Email)
|
||||||
userIdStr := fmt.Sprintf("%v", user.ID)
|
userIdStr := fmt.Sprintf("%v", user.ID)
|
||||||
|
|
||||||
refreshToken, _, _ := utils.CreateAuthToken(utils.UserAuthInfo{
|
refreshToken, _, _ := utils.CreateAuthToken(utils.UserAuthInfo{
|
||||||
ID: userIdStr,
|
ID: userIdStr,
|
||||||
Email: user.Email,
|
Email: user.Email,
|
||||||
|
@ -139,6 +140,7 @@ func processGithubUserInfo(code string, c *gin.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
user, _ = db.Mgr.SaveUser(user)
|
user, _ = db.Mgr.SaveUser(user)
|
||||||
|
user, _ = db.Mgr.GetUserByEmail(user.Email)
|
||||||
userIdStr := fmt.Sprintf("%v", user.ID)
|
userIdStr := fmt.Sprintf("%v", user.ID)
|
||||||
refreshToken, _, _ := utils.CreateAuthToken(utils.UserAuthInfo{
|
refreshToken, _, _ := utils.CreateAuthToken(utils.UserAuthInfo{
|
||||||
ID: userIdStr,
|
ID: userIdStr,
|
||||||
|
@ -156,17 +158,16 @@ func processGithubUserInfo(code string, c *gin.Context) error {
|
||||||
|
|
||||||
func OAuthCallbackHandler() gin.HandlerFunc {
|
func OAuthCallbackHandler() gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
log.Println("url:", c.Request.URL)
|
|
||||||
provider := c.Param("oauth_provider")
|
provider := c.Param("oauth_provider")
|
||||||
state := c.Request.FormValue("state")
|
state := c.Request.FormValue("state")
|
||||||
log.Println("session state", state)
|
|
||||||
sessionState := session.GetToken(state)
|
sessionState := session.GetToken(state)
|
||||||
if sessionState == "" {
|
if sessionState == "" {
|
||||||
c.JSON(400, gin.H{"error": "invalid oauth state"})
|
c.JSON(400, gin.H{"error": "invalid oauth state"})
|
||||||
}
|
}
|
||||||
session.DeleteToken(sessionState)
|
session.DeleteToken(sessionState)
|
||||||
sessionSplit := strings.Split(state, "___")
|
sessionSplit := strings.Split(state, "___")
|
||||||
log.Println(sessionSplit)
|
|
||||||
// TODO validate redirect url
|
// TODO validate redirect url
|
||||||
if len(sessionSplit) != 2 {
|
if len(sessionSplit) != 2 {
|
||||||
c.JSON(400, gin.H{"error": "invalid redirect url"})
|
c.JSON(400, gin.H{"error": "invalid redirect url"})
|
||||||
|
|
|
@ -18,15 +18,15 @@ func ResetPassword(ctx context.Context, params model.ResetPasswordInput) (*model
|
||||||
return res, fmt.Errorf(`basic authentication is disabled for this instance`)
|
return res, fmt.Errorf(`basic authentication is disabled for this instance`)
|
||||||
}
|
}
|
||||||
|
|
||||||
if params.Password != params.ConfirmPassword {
|
|
||||||
return res, fmt.Errorf(`passwords don't match`)
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := db.Mgr.GetVerificationByToken(params.Token)
|
_, err := db.Mgr.GetVerificationByToken(params.Token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, fmt.Errorf(`invalid token`)
|
return res, fmt.Errorf(`invalid token`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if params.Password != params.ConfirmPassword {
|
||||||
|
return res, fmt.Errorf(`passwords don't match`)
|
||||||
|
}
|
||||||
|
|
||||||
// verify if token exists in db
|
// verify if token exists in db
|
||||||
claim, err := utils.VerifyVerificationToken(params.Token)
|
claim, err := utils.VerifyVerificationToken(params.Token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user