From 6ecd5405657a69e1bfc21c594ff550285e642ca3 Mon Sep 17 00:00:00 2001 From: LiusCraft Date: Mon, 19 Feb 2024 19:55:43 +0800 Subject: [PATCH] fix: bind account --- .gitignore | 1 + cmd/gopcomm/community_yap.gox | 82 +- cmd/gopcomm/gop_autogen.go | 467 +++--- cmd/gopcomm/yap/static/js/user_edit.js | 1828 ++++++++---------------- cmd/gopcomm/yap/user_edit_yap.html | 16 +- internal/core/casdoor.go | 79 + internal/core/casdoor_test.go | 42 + internal/core/user.go | 3 +- 8 files changed, 1079 insertions(+), 1439 deletions(-) create mode 100644 internal/core/casdoor.go create mode 100644 internal/core/casdoor_test.go diff --git a/.gitignore b/.gitignore index e501aeb9..188b368a 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,4 @@ go.work # gop_autogen.go dist/ node_modules/ +.vscode/ diff --git a/cmd/gopcomm/community_yap.gox b/cmd/gopcomm/community_yap.gox index 6ba77597..22efca97 100644 --- a/cmd/gopcomm/community_yap.gox +++ b/cmd/gopcomm/community_yap.gox @@ -74,10 +74,10 @@ get "/p/:id", ctx => { "Title": article.Title, "Content": article.Content, // "HtmlUrl": article.HtmlUrl, - "Tags": article.Tags, - "Cover": article.Cover, - "Mtime": article.Mtime.Format(layoutUS), - "Author": article.User, + "Tags": article.Tags, + "Cover": article.Cover, + "Mtime": article.Mtime.Format(layoutUS), + "Author": article.User, // "User": article.User, } } @@ -120,7 +120,24 @@ get "/user/:id", ctx => { "UserId": user.Id, } } +get "/userUnlink", ctx => { + pv := ctx.param("pv") + switch pv { + case "Twitter": + case "Facebook": + case "Github": + case "WeChat": + default: + http.Redirect(ctx.ResponseWriter, ctx.Request, "/userEdit", http.StatusTemporaryRedirect) + } + token, err := core.GetToken(ctx) + if err == nil { + http.Redirect(ctx.ResponseWriter, ctx.Request, "/userEdit", http.StatusTemporaryRedirect) + } + community.UnLink(token.Value, pv) + http.Redirect(ctx.ResponseWriter, ctx.Request, "/userEdit", http.StatusTemporaryRedirect) +} get "/userEdit", ctx => { var user *core.User token, err := core.GetToken(ctx) @@ -134,8 +151,15 @@ get "/userEdit", ctx => { if err != nil { http.Redirect(ctx.ResponseWriter, ctx.Request, "/error", http.StatusTemporaryRedirect) } + appInfo, err := community.GetApplicationInfo() + if err != nil { + http.Redirect(ctx.ResponseWriter, ctx.Request, "/error", http.StatusTemporaryRedirect) + } + appInfoStr, _ := json.Marshal(*appInfo) ctx.yap "user_edit", { - "User": user, + "User": user, + "Application": string(appInfoStr), + "Binds": community.GetAccountBinds(token.Value), } } @@ -149,7 +173,7 @@ get "/add", ctx => { } } ctx.yap "edit", { - "User": user, + "User": user, } } @@ -347,7 +371,7 @@ post "/commit", ctx => { // get user id token, err := core.GetToken(ctx) if err != nil { - xLog.Info("token",err) + xLog.Info("token", err) ctx.json { "code": 0, "err": "no token", @@ -355,7 +379,7 @@ post "/commit", ctx => { } uid, err := community.ParseJwtToken(token.Value) if err != nil { - xLog.Info("uid",err) + xLog.Info("uid", err) ctx.json { "code": 0, "err": err.Error(), @@ -367,11 +391,11 @@ post "/commit", ctx => { ID: id, Title: ctx.param("title"), UId: uid, - Cover: ctx.param("cover"), + Cover: ctx.param("cover"), Tags: ctx.param("tags"), Abstract: ctx.param("abstract"), }, - Content: mdData, + Content: mdData, TransContent: transData, } id, _ = community.PutArticle(todo, uid, article) @@ -450,26 +474,26 @@ get "/getMediaUrl/:id", ctx => { get "/getVideoAndSubtitle/:id", ctx => { id := ctx.param("id") fileKey, err := community.GetMediaUrl(todo, id) - m:=make(map[string]string,2) - format,err:=community.GetMediaType(todo,id) - if err!=nil { - ctx.json { - "code": 500, - "err": err.Error(), - } + m := make(map[string]string, 2) + format, err := community.GetMediaType(todo, id) + if err != nil { + ctx.json { + "code": 500, + "err": err.Error(), + } } if format == "video/mp4" { - subtitle,err:=community.GetVideoSubtitle(todo,id) - if err!=nil{ - if err != nil { - ctx.json { - "code": 500, - "err": err.Error(), - } - } - return - } - m["subtitle"] = domain+subtitle + subtitle, err := community.GetVideoSubtitle(todo, id) + if err != nil { + if err != nil { + ctx.json { + "code": 500, + "err": err.Error(), + } + } + return + } + m["subtitle"] = domain + subtitle } htmlUrl := fmt.Sprintf("%s%s", domain, fileKey) if err != nil { @@ -539,7 +563,7 @@ get "/callback", ctx => { origin_path := ctx.URL.Query().Get("origin_path") unurl, err := url.QueryUnescape(origin_path) if err != nil { - xLog.Info("Unurl error",err) + xLog.Info("Unurl error", err) unurl = "/" } diff --git a/cmd/gopcomm/gop_autogen.go b/cmd/gopcomm/gop_autogen.go index a2674b00..6c6574d8 100644 --- a/cmd/gopcomm/gop_autogen.go +++ b/cmd/gopcomm/gop_autogen.go @@ -1,22 +1,23 @@ package main import ( - "fmt" - "os" - "strconv" - "strings" - "github.com/goplus/yap" "context" "encoding/json" - "net/http" - "net/url" + "fmt" "github.com/goplus/community/internal/core" "github.com/goplus/community/translation" + "github.com/goplus/yap" _ "github.com/joho/godotenv/autoload" "github.com/qiniu/x/xlog" "golang.org/x/text/language" + "net/http" + "net/url" + "os" + "strconv" + "strings" ) +const _ = true const ( layoutUS = "January 2, 2006" limitConst = 10 @@ -142,508 +143,548 @@ func (this *community) MainEntry() { ctx.Yap__1("user", map[string]interface { }{"Id": id, "CurrentUser": strings.Replace(string(userClaimJson), `\"`, `"`, -1), "User": user, "Items": strings.Replace(string(itemsJson), `\"`, `"`, -1), "UserId": user.Id}) }) +//line cmd/gopcomm/community_yap.gox:123:1 + this.Get("/userUnlink", func(ctx *yap.Context) { //line cmd/gopcomm/community_yap.gox:124:1 - this.Get("/userEdit", func(ctx *yap.Context) { + pv := ctx.Param("pv") //line cmd/gopcomm/community_yap.gox:125:1 - var user *core.User + switch pv { //line cmd/gopcomm/community_yap.gox:126:1 - token, err := core.GetToken(ctx) + case "Twitter": //line cmd/gopcomm/community_yap.gox:127:1 - if err == nil { + case "Facebook": //line cmd/gopcomm/community_yap.gox:128:1 - user, err = this.community.GetUser(token.Value) + case "Github": //line cmd/gopcomm/community_yap.gox:129:1 - if err != nil { + case "WeChat": //line cmd/gopcomm/community_yap.gox:130:1 + default: +//line cmd/gopcomm/community_yap.gox:131:1 + http.Redirect(ctx.ResponseWriter, ctx.Request, "/userEdit", http.StatusTemporaryRedirect) + } +//line cmd/gopcomm/community_yap.gox:133:1 + token, err := core.GetToken(ctx) +//line cmd/gopcomm/community_yap.gox:134:1 + if err == nil { +//line cmd/gopcomm/community_yap.gox:135:1 + http.Redirect(ctx.ResponseWriter, ctx.Request, "/userEdit", http.StatusTemporaryRedirect) + } +//line cmd/gopcomm/community_yap.gox:138:1 + this.community.UnLink(token.Value, pv) +//line cmd/gopcomm/community_yap.gox:139:1 + http.Redirect(ctx.ResponseWriter, ctx.Request, "/userEdit", http.StatusTemporaryRedirect) + }) +//line cmd/gopcomm/community_yap.gox:141:1 + this.Get("/userEdit", func(ctx *yap.Context) { +//line cmd/gopcomm/community_yap.gox:142:1 + var user *core.User +//line cmd/gopcomm/community_yap.gox:143:1 + token, err := core.GetToken(ctx) +//line cmd/gopcomm/community_yap.gox:144:1 + if err == nil { +//line cmd/gopcomm/community_yap.gox:145:1 + user, err = this.community.GetUser(token.Value) +//line cmd/gopcomm/community_yap.gox:146:1 + if err != nil { +//line cmd/gopcomm/community_yap.gox:147:1 xLog.Error("get user error:", err) } } -//line cmd/gopcomm/community_yap.gox:134:1 +//line cmd/gopcomm/community_yap.gox:151:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:135:1 +//line cmd/gopcomm/community_yap.gox:152:1 + http.Redirect(ctx.ResponseWriter, ctx.Request, "/error", http.StatusTemporaryRedirect) + } +//line cmd/gopcomm/community_yap.gox:154:1 + appInfo, err := this.community.GetApplicationInfo() +//line cmd/gopcomm/community_yap.gox:155:1 + if err != nil { +//line cmd/gopcomm/community_yap.gox:156:1 http.Redirect(ctx.ResponseWriter, ctx.Request, "/error", http.StatusTemporaryRedirect) } -//line cmd/gopcomm/community_yap.gox:137:1 - ctx.Yap__1("user_edit", map[string]*core.User{"User": user}) +//line cmd/gopcomm/community_yap.gox:158:1 + appInfoStr, _ := json.Marshal(*appInfo) +//line cmd/gopcomm/community_yap.gox:159:1 + ctx.Yap__1("user_edit", map[string]interface { + }{"User": user, "Application": string(appInfoStr), "Binds": this.community.GetAccountBinds(token.Value)}) }) -//line cmd/gopcomm/community_yap.gox:142:1 +//line cmd/gopcomm/community_yap.gox:166:1 this.Get("/add", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:143:1 +//line cmd/gopcomm/community_yap.gox:167:1 var user *core.User -//line cmd/gopcomm/community_yap.gox:144:1 +//line cmd/gopcomm/community_yap.gox:168:1 token, err := core.GetToken(ctx) -//line cmd/gopcomm/community_yap.gox:145:1 +//line cmd/gopcomm/community_yap.gox:169:1 if err == nil { -//line cmd/gopcomm/community_yap.gox:146:1 +//line cmd/gopcomm/community_yap.gox:170:1 user, err = this.community.GetUser(token.Value) -//line cmd/gopcomm/community_yap.gox:147:1 +//line cmd/gopcomm/community_yap.gox:171:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:148:1 +//line cmd/gopcomm/community_yap.gox:172:1 xLog.Error("get user error:", err) } } -//line cmd/gopcomm/community_yap.gox:151:1 +//line cmd/gopcomm/community_yap.gox:175:1 ctx.Yap__1("edit", map[string]*core.User{"User": user}) }) -//line cmd/gopcomm/community_yap.gox:156:1 +//line cmd/gopcomm/community_yap.gox:180:1 this.Get("/delete", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:157:1 +//line cmd/gopcomm/community_yap.gox:181:1 id := ctx.Param("id") -//line cmd/gopcomm/community_yap.gox:158:1 +//line cmd/gopcomm/community_yap.gox:182:1 token, err := core.GetToken(ctx) -//line cmd/gopcomm/community_yap.gox:159:1 +//line cmd/gopcomm/community_yap.gox:183:1 uid, err := this.community.ParseJwtToken(token.Value) -//line cmd/gopcomm/community_yap.gox:160:1 +//line cmd/gopcomm/community_yap.gox:184:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:161:1 +//line cmd/gopcomm/community_yap.gox:185:1 xLog.Error("token parse error") -//line cmd/gopcomm/community_yap.gox:162:1 +//line cmd/gopcomm/community_yap.gox:186:1 ctx.Json__1(map[string]interface { }{"code": 0, "err": err.Error()}) } -//line cmd/gopcomm/community_yap.gox:167:1 +//line cmd/gopcomm/community_yap.gox:191:1 err = this.community.DeleteArticle(todo, uid, id) -//line cmd/gopcomm/community_yap.gox:168:1 +//line cmd/gopcomm/community_yap.gox:192:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:169:1 +//line cmd/gopcomm/community_yap.gox:193:1 ctx.Json__1(map[string]interface { }{"code": 0, "err": "delete failed"}) } else { -//line cmd/gopcomm/community_yap.gox:174:1 +//line cmd/gopcomm/community_yap.gox:198:1 ctx.Json__1(map[string]interface { }{"code": 200, "msg": "delete success"}) } }) -//line cmd/gopcomm/community_yap.gox:181:1 +//line cmd/gopcomm/community_yap.gox:205:1 this.Get("/medias", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:182:1 +//line cmd/gopcomm/community_yap.gox:206:1 format := ctx.Param("format") -//line cmd/gopcomm/community_yap.gox:183:1 +//line cmd/gopcomm/community_yap.gox:207:1 uid := ctx.Param("uid") -//line cmd/gopcomm/community_yap.gox:184:1 +//line cmd/gopcomm/community_yap.gox:208:1 files, err := this.community.ListMediaByUserId(todo, uid, format) -//line cmd/gopcomm/community_yap.gox:185:1 +//line cmd/gopcomm/community_yap.gox:209:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:186:1 +//line cmd/gopcomm/community_yap.gox:210:1 ctx.Json__1(map[string]interface { }{"code": 0, "err": "get media failed"}) } else { -//line cmd/gopcomm/community_yap.gox:191:1 +//line cmd/gopcomm/community_yap.gox:215:1 ctx.Json__1(map[string]interface { }{"code": 200, "items": files}) } }) -//line cmd/gopcomm/community_yap.gox:198:1 +//line cmd/gopcomm/community_yap.gox:222:1 this.Get("/delMedia", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:199:1 +//line cmd/gopcomm/community_yap.gox:223:1 id := ctx.Param("id") -//line cmd/gopcomm/community_yap.gox:200:1 +//line cmd/gopcomm/community_yap.gox:224:1 token, err := core.GetToken(ctx) -//line cmd/gopcomm/community_yap.gox:201:1 +//line cmd/gopcomm/community_yap.gox:225:1 uid, err := this.community.ParseJwtToken(token.Value) -//line cmd/gopcomm/community_yap.gox:202:1 +//line cmd/gopcomm/community_yap.gox:226:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:203:1 +//line cmd/gopcomm/community_yap.gox:227:1 xLog.Error("token parse error") -//line cmd/gopcomm/community_yap.gox:204:1 +//line cmd/gopcomm/community_yap.gox:228:1 ctx.Json__1(map[string]interface { }{"code": 0, "err": err.Error()}) } -//line cmd/gopcomm/community_yap.gox:209:1 +//line cmd/gopcomm/community_yap.gox:233:1 err = this.community.DelMedia(todo, uid, id) -//line cmd/gopcomm/community_yap.gox:210:1 +//line cmd/gopcomm/community_yap.gox:234:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:211:1 +//line cmd/gopcomm/community_yap.gox:235:1 ctx.Json__1(map[string]interface { }{"code": 0, "err": "delete failed"}) } else { -//line cmd/gopcomm/community_yap.gox:216:1 +//line cmd/gopcomm/community_yap.gox:240:1 ctx.Json__1(map[string]interface { }{"code": 200, "msg": "delete success"}) } }) -//line cmd/gopcomm/community_yap.gox:223:1 +//line cmd/gopcomm/community_yap.gox:247:1 this.Get("/", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:225:1 +//line cmd/gopcomm/community_yap.gox:249:1 // Get User Info var user *core.User -//line cmd/gopcomm/community_yap.gox:226:1 +//line cmd/gopcomm/community_yap.gox:250:1 userId := "" -//line cmd/gopcomm/community_yap.gox:227:1 +//line cmd/gopcomm/community_yap.gox:251:1 token, err := core.GetToken(ctx) -//line cmd/gopcomm/community_yap.gox:228:1 +//line cmd/gopcomm/community_yap.gox:252:1 if err == nil { -//line cmd/gopcomm/community_yap.gox:229:1 +//line cmd/gopcomm/community_yap.gox:253:1 user, err = this.community.GetUser(token.Value) -//line cmd/gopcomm/community_yap.gox:230:1 +//line cmd/gopcomm/community_yap.gox:254:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:231:1 +//line cmd/gopcomm/community_yap.gox:255:1 xLog.Error("get user error:", err) } else { -//line cmd/gopcomm/community_yap.gox:233:1 +//line cmd/gopcomm/community_yap.gox:257:1 userId = user.Id } } -//line cmd/gopcomm/community_yap.gox:237:1 +//line cmd/gopcomm/community_yap.gox:261:1 articles, next, _ := this.community.ListArticle(todo, core.MarkBegin, limitConst, "") -//line cmd/gopcomm/community_yap.gox:238:1 +//line cmd/gopcomm/community_yap.gox:262:1 articlesJson, _ := json.Marshal(&articles) -//line cmd/gopcomm/community_yap.gox:239:1 +//line cmd/gopcomm/community_yap.gox:263:1 ctx.Yap__1("home", map[string]interface { }{"UserId": userId, "User": user, "Items": strings.Replace(string(articlesJson), `\"`, `"`, -1), "Next": next}) }) -//line cmd/gopcomm/community_yap.gox:247:1 +//line cmd/gopcomm/community_yap.gox:271:1 this.Get("/get", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:248:1 +//line cmd/gopcomm/community_yap.gox:272:1 from := ctx.Param("from") -//line cmd/gopcomm/community_yap.gox:249:1 +//line cmd/gopcomm/community_yap.gox:273:1 limit := ctx.Param("limit") -//line cmd/gopcomm/community_yap.gox:250:1 +//line cmd/gopcomm/community_yap.gox:274:1 searchValue := ctx.Param("value") -//line cmd/gopcomm/community_yap.gox:252:1 +//line cmd/gopcomm/community_yap.gox:276:1 limitInt, err := strconv.Atoi(limit) -//line cmd/gopcomm/community_yap.gox:253:1 +//line cmd/gopcomm/community_yap.gox:277:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:254:1 +//line cmd/gopcomm/community_yap.gox:278:1 limitInt = limitConst } -//line cmd/gopcomm/community_yap.gox:257:1 +//line cmd/gopcomm/community_yap.gox:281:1 articles, next, _ := this.community.ListArticle(todo, from, limitInt, searchValue) -//line cmd/gopcomm/community_yap.gox:258:1 +//line cmd/gopcomm/community_yap.gox:282:1 ctx.Json__1(map[string]interface { }{"code": 200, "items": articles, "next": next, "value": searchValue}) }) -//line cmd/gopcomm/community_yap.gox:266:1 +//line cmd/gopcomm/community_yap.gox:290:1 this.Get("/search", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:267:1 +//line cmd/gopcomm/community_yap.gox:291:1 searchValue := ctx.Param("value") -//line cmd/gopcomm/community_yap.gox:276:1 +//line cmd/gopcomm/community_yap.gox:300:1 // todo middleware var user *core.User -//line cmd/gopcomm/community_yap.gox:277:1 +//line cmd/gopcomm/community_yap.gox:301:1 userId := "" -//line cmd/gopcomm/community_yap.gox:278:1 +//line cmd/gopcomm/community_yap.gox:302:1 token, err := core.GetToken(ctx) -//line cmd/gopcomm/community_yap.gox:279:1 +//line cmd/gopcomm/community_yap.gox:303:1 if err == nil { -//line cmd/gopcomm/community_yap.gox:280:1 +//line cmd/gopcomm/community_yap.gox:304:1 user, err = this.community.GetUser(token.Value) -//line cmd/gopcomm/community_yap.gox:281:1 +//line cmd/gopcomm/community_yap.gox:305:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:282:1 +//line cmd/gopcomm/community_yap.gox:306:1 xLog.Error("get user error:", err) } else { -//line cmd/gopcomm/community_yap.gox:284:1 +//line cmd/gopcomm/community_yap.gox:308:1 userId = user.Id } } -//line cmd/gopcomm/community_yap.gox:288:1 +//line cmd/gopcomm/community_yap.gox:312:1 articles, next, _ := this.community.ListArticle(todo, core.MarkBegin, limitConst, searchValue) -//line cmd/gopcomm/community_yap.gox:289:1 +//line cmd/gopcomm/community_yap.gox:313:1 articlesJson, _ := json.Marshal(&articles) -//line cmd/gopcomm/community_yap.gox:290:1 +//line cmd/gopcomm/community_yap.gox:314:1 ctx.Yap__1("home", map[string]interface { }{"UserId": userId, "User": user, "Items": strings.Replace(string(articlesJson), `\"`, `"`, -1), "Value": searchValue, "Next": next}) }) -//line cmd/gopcomm/community_yap.gox:299:1 +//line cmd/gopcomm/community_yap.gox:323:1 this.Get("/edit/:id", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:300:1 +//line cmd/gopcomm/community_yap.gox:324:1 var user *core.User -//line cmd/gopcomm/community_yap.gox:301:1 +//line cmd/gopcomm/community_yap.gox:325:1 token, err := core.GetToken(ctx) -//line cmd/gopcomm/community_yap.gox:302:1 +//line cmd/gopcomm/community_yap.gox:326:1 if err == nil { -//line cmd/gopcomm/community_yap.gox:303:1 +//line cmd/gopcomm/community_yap.gox:327:1 user, err = this.community.GetUser(token.Value) -//line cmd/gopcomm/community_yap.gox:304:1 +//line cmd/gopcomm/community_yap.gox:328:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:305:1 +//line cmd/gopcomm/community_yap.gox:329:1 xLog.Error("get user error:", err) } } -//line cmd/gopcomm/community_yap.gox:309:1 +//line cmd/gopcomm/community_yap.gox:333:1 uid := user.Id -//line cmd/gopcomm/community_yap.gox:310:1 +//line cmd/gopcomm/community_yap.gox:334:1 id := ctx.Param("id") -//line cmd/gopcomm/community_yap.gox:311:1 +//line cmd/gopcomm/community_yap.gox:335:1 if id != "" { -//line cmd/gopcomm/community_yap.gox:312:1 +//line cmd/gopcomm/community_yap.gox:336:1 if -//line cmd/gopcomm/community_yap.gox:312:1 +//line cmd/gopcomm/community_yap.gox:336:1 editable, _ := this.community.CanEditable(todo, uid, id); !editable { -//line cmd/gopcomm/community_yap.gox:313:1 +//line cmd/gopcomm/community_yap.gox:337:1 xLog.Error("no permissions") -//line cmd/gopcomm/community_yap.gox:314:1 +//line cmd/gopcomm/community_yap.gox:338:1 http.Redirect(ctx.ResponseWriter, ctx.Request, "/error", http.StatusTemporaryRedirect) } -//line cmd/gopcomm/community_yap.gox:316:1 +//line cmd/gopcomm/community_yap.gox:340:1 article, _ := this.community.Article(todo, id) -//line cmd/gopcomm/community_yap.gox:317:1 +//line cmd/gopcomm/community_yap.gox:341:1 articleJson, _ := json.Marshal(&article) -//line cmd/gopcomm/community_yap.gox:318:1 +//line cmd/gopcomm/community_yap.gox:342:1 ctx.Yap__1("edit", map[string]interface { }{"User": user, "Article": strings.Replace(string(articleJson), `\"`, `"`, -1)}) } }) -//line cmd/gopcomm/community_yap.gox:325:1 +//line cmd/gopcomm/community_yap.gox:349:1 this.Get("/getTrans", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:326:1 +//line cmd/gopcomm/community_yap.gox:350:1 id := ctx.Param("id") -//line cmd/gopcomm/community_yap.gox:327:1 +//line cmd/gopcomm/community_yap.gox:351:1 htmlUrl, err := this.community.TransHtmlUrl(todo, id) -//line cmd/gopcomm/community_yap.gox:328:1 +//line cmd/gopcomm/community_yap.gox:352:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:329:1 +//line cmd/gopcomm/community_yap.gox:353:1 ctx.Json__1(map[string]interface { }{"code": 500, "err": err.Error()}) } -//line cmd/gopcomm/community_yap.gox:334:1 +//line cmd/gopcomm/community_yap.gox:358:1 ctx.Json__1(map[string]interface { }{"code": 200, "data": htmlUrl}) }) -//line cmd/gopcomm/community_yap.gox:341:1 +//line cmd/gopcomm/community_yap.gox:365:1 this.Post("/commit", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:344:1 +//line cmd/gopcomm/community_yap.gox:368:1 id := ctx.Param("id") -//line cmd/gopcomm/community_yap.gox:345:1 +//line cmd/gopcomm/community_yap.gox:369:1 mdData := ctx.Param("content") -//line cmd/gopcomm/community_yap.gox:346:1 +//line cmd/gopcomm/community_yap.gox:370:1 transData := ctx.Param("trans_data") -//line cmd/gopcomm/community_yap.gox:348:1 +//line cmd/gopcomm/community_yap.gox:372:1 token, err := core.GetToken(ctx) -//line cmd/gopcomm/community_yap.gox:349:1 +//line cmd/gopcomm/community_yap.gox:373:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:350:1 +//line cmd/gopcomm/community_yap.gox:374:1 xLog.Info("token", err) -//line cmd/gopcomm/community_yap.gox:351:1 +//line cmd/gopcomm/community_yap.gox:375:1 ctx.Json__1(map[string]interface { }{"code": 0, "err": "no token"}) } -//line cmd/gopcomm/community_yap.gox:356:1 +//line cmd/gopcomm/community_yap.gox:380:1 uid, err := this.community.ParseJwtToken(token.Value) -//line cmd/gopcomm/community_yap.gox:357:1 +//line cmd/gopcomm/community_yap.gox:381:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:358:1 +//line cmd/gopcomm/community_yap.gox:382:1 xLog.Info("uid", err) -//line cmd/gopcomm/community_yap.gox:359:1 +//line cmd/gopcomm/community_yap.gox:383:1 ctx.Json__1(map[string]interface { }{"code": 0, "err": err.Error()}) } -//line cmd/gopcomm/community_yap.gox:365:1 +//line cmd/gopcomm/community_yap.gox:389:1 article := &core.Article{ArticleEntry: core.ArticleEntry{ID: id, Title: ctx.Param("title"), UId: uid, Cover: ctx.Param("cover"), Tags: ctx.Param("tags"), Abstract: ctx.Param("abstract")}, Content: mdData, TransContent: transData} -//line cmd/gopcomm/community_yap.gox:377:1 - id, err = this.community.PutArticle(todo, uid, article) -//line cmd/gopcomm/community_yap.gox:378:1 - xLog.Info("err", err) -//line cmd/gopcomm/community_yap.gox:379:1 +//line cmd/gopcomm/community_yap.gox:401:1 + id, _ = this.community.PutArticle(todo, uid, article) +//line cmd/gopcomm/community_yap.gox:402:1 ctx.Json__1(map[string]interface { }{"code": 200, "data": id}) }) -//line cmd/gopcomm/community_yap.gox:387:1 +//line cmd/gopcomm/community_yap.gox:410:1 this.Post("/translate", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:404:1 +//line cmd/gopcomm/community_yap.gox:427:1 mdData := ctx.Param("content") -//line cmd/gopcomm/community_yap.gox:408:1 +//line cmd/gopcomm/community_yap.gox:431:1 transData, err := this.community.TranslateMarkdownText(todo, mdData, language.Chinese, language.English) -//line cmd/gopcomm/community_yap.gox:409:1 +//line cmd/gopcomm/community_yap.gox:432:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:410:1 +//line cmd/gopcomm/community_yap.gox:433:1 ctx.Json__1(map[string]interface { }{"code": 500, "err": err.Error()}) } -//line cmd/gopcomm/community_yap.gox:415:1 +//line cmd/gopcomm/community_yap.gox:438:1 ctx.Json__1(map[string]interface { }{"code": 200, "data": transData}) }) -//line cmd/gopcomm/community_yap.gox:427:1 +//line cmd/gopcomm/community_yap.gox:450:1 this.Get("/getMedia/:id", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:428:1 +//line cmd/gopcomm/community_yap.gox:451:1 mediaId := ctx.Param("id") -//line cmd/gopcomm/community_yap.gox:430:1 +//line cmd/gopcomm/community_yap.gox:453:1 fileKey, _ := this.community.GetMediaUrl(context.Background(), mediaId) -//line cmd/gopcomm/community_yap.gox:432:1 +//line cmd/gopcomm/community_yap.gox:455:1 http.Redirect(ctx.ResponseWriter, ctx.Request, domain+fileKey, http.StatusTemporaryRedirect) }) -//line cmd/gopcomm/community_yap.gox:435:1 +//line cmd/gopcomm/community_yap.gox:458:1 this.Get("/getMediaUrl/:id", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:436:1 +//line cmd/gopcomm/community_yap.gox:459:1 id := ctx.Param("id") -//line cmd/gopcomm/community_yap.gox:437:1 +//line cmd/gopcomm/community_yap.gox:460:1 fileKey, err := this.community.GetMediaUrl(todo, id) -//line cmd/gopcomm/community_yap.gox:438:1 +//line cmd/gopcomm/community_yap.gox:461:1 htmlUrl := fmt.Sprintf("%s%s", domain, fileKey) -//line cmd/gopcomm/community_yap.gox:439:1 +//line cmd/gopcomm/community_yap.gox:462:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:440:1 +//line cmd/gopcomm/community_yap.gox:463:1 ctx.Json__1(map[string]interface { }{"code": 500, "err": "have no html media"}) } -//line cmd/gopcomm/community_yap.gox:445:1 +//line cmd/gopcomm/community_yap.gox:468:1 ctx.Json__1(map[string]interface { }{"code": 200, "url": htmlUrl}) }) -//line cmd/gopcomm/community_yap.gox:451:1 +//line cmd/gopcomm/community_yap.gox:474:1 this.Get("/getVideoAndSubtitle/:id", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:452:1 +//line cmd/gopcomm/community_yap.gox:475:1 id := ctx.Param("id") -//line cmd/gopcomm/community_yap.gox:453:1 +//line cmd/gopcomm/community_yap.gox:476:1 fileKey, err := this.community.GetMediaUrl(todo, id) -//line cmd/gopcomm/community_yap.gox:454:1 +//line cmd/gopcomm/community_yap.gox:477:1 m := make(map[string]string, 2) -//line cmd/gopcomm/community_yap.gox:455:1 +//line cmd/gopcomm/community_yap.gox:478:1 format, err := this.community.GetMediaType(todo, id) -//line cmd/gopcomm/community_yap.gox:456:1 +//line cmd/gopcomm/community_yap.gox:479:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:457:1 +//line cmd/gopcomm/community_yap.gox:480:1 ctx.Json__1(map[string]interface { }{"code": 500, "err": err.Error()}) } -//line cmd/gopcomm/community_yap.gox:462:1 +//line cmd/gopcomm/community_yap.gox:485:1 if format == "video/mp4" { -//line cmd/gopcomm/community_yap.gox:463:1 +//line cmd/gopcomm/community_yap.gox:486:1 subtitle, err := this.community.GetVideoSubtitle(todo, id) -//line cmd/gopcomm/community_yap.gox:464:1 +//line cmd/gopcomm/community_yap.gox:487:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:465:1 +//line cmd/gopcomm/community_yap.gox:488:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:466:1 +//line cmd/gopcomm/community_yap.gox:489:1 ctx.Json__1(map[string]interface { }{"code": 500, "err": err.Error()}) } -//line cmd/gopcomm/community_yap.gox:471:1 +//line cmd/gopcomm/community_yap.gox:494:1 return } -//line cmd/gopcomm/community_yap.gox:473:1 +//line cmd/gopcomm/community_yap.gox:496:1 m["subtitle"] = domain + subtitle } -//line cmd/gopcomm/community_yap.gox:475:1 +//line cmd/gopcomm/community_yap.gox:498:1 htmlUrl := fmt.Sprintf("%s%s", domain, fileKey) -//line cmd/gopcomm/community_yap.gox:476:1 +//line cmd/gopcomm/community_yap.gox:499:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:477:1 +//line cmd/gopcomm/community_yap.gox:500:1 ctx.Json__1(map[string]interface { }{"code": 500, "err": "have no html media"}) } -//line cmd/gopcomm/community_yap.gox:482:1 +//line cmd/gopcomm/community_yap.gox:505:1 m["fileKey"] = htmlUrl -//line cmd/gopcomm/community_yap.gox:483:1 +//line cmd/gopcomm/community_yap.gox:506:1 ctx.Json__1(map[string]interface { }{"code": 200, "url": m}) }) -//line cmd/gopcomm/community_yap.gox:489:1 +//line cmd/gopcomm/community_yap.gox:512:1 this.Post("/upload", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:490:1 +//line cmd/gopcomm/community_yap.gox:513:1 this.community.UploadFile(ctx) }) -//line cmd/gopcomm/community_yap.gox:493:1 +//line cmd/gopcomm/community_yap.gox:516:1 this.Get("/login", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:498:1 +//line cmd/gopcomm/community_yap.gox:521:1 refererURL, err := url.Parse(ctx.Request.Referer()) -//line cmd/gopcomm/community_yap.gox:499:1 +//line cmd/gopcomm/community_yap.gox:522:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:500:1 +//line cmd/gopcomm/community_yap.gox:523:1 xLog.Info("Error parsing Referer: %v", err) -//line cmd/gopcomm/community_yap.gox:501:1 +//line cmd/gopcomm/community_yap.gox:524:1 return } -//line cmd/gopcomm/community_yap.gox:504:1 +//line cmd/gopcomm/community_yap.gox:527:1 refererPath := refererURL.Path -//line cmd/gopcomm/community_yap.gox:505:1 +//line cmd/gopcomm/community_yap.gox:528:1 if refererURL.RawQuery != "" { -//line cmd/gopcomm/community_yap.gox:506:1 +//line cmd/gopcomm/community_yap.gox:529:1 refererPath = fmt.Sprintf("%s?%s", refererURL.Path, refererURL.RawQuery) } -//line cmd/gopcomm/community_yap.gox:509:1 +//line cmd/gopcomm/community_yap.gox:532:1 redirectURL := fmt.Sprintf("%s://%s/%s?origin_path=%s", refererURL.Scheme, refererURL.Host, "callback", url.QueryEscape(refererPath)) -//line cmd/gopcomm/community_yap.gox:511:1 +//line cmd/gopcomm/community_yap.gox:534:1 loginURL := this.community.RedirectToCasdoor(redirectURL) -//line cmd/gopcomm/community_yap.gox:512:1 +//line cmd/gopcomm/community_yap.gox:535:1 ctx.Redirect(loginURL, http.StatusFound) }) -//line cmd/gopcomm/community_yap.gox:515:1 +//line cmd/gopcomm/community_yap.gox:538:1 this.Get("/logout", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:516:1 +//line cmd/gopcomm/community_yap.gox:539:1 err := core.RemoveToken(ctx) -//line cmd/gopcomm/community_yap.gox:517:1 +//line cmd/gopcomm/community_yap.gox:540:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:518:1 +//line cmd/gopcomm/community_yap.gox:541:1 xLog.Error("remove token error:", err) } -//line cmd/gopcomm/community_yap.gox:521:1 +//line cmd/gopcomm/community_yap.gox:544:1 refererURL, err := url.Parse(ctx.Request.Referer()) -//line cmd/gopcomm/community_yap.gox:522:1 +//line cmd/gopcomm/community_yap.gox:545:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:523:1 +//line cmd/gopcomm/community_yap.gox:546:1 xLog.Info("Error parsing Referer: %v", err) -//line cmd/gopcomm/community_yap.gox:524:1 +//line cmd/gopcomm/community_yap.gox:547:1 return } -//line cmd/gopcomm/community_yap.gox:527:1 +//line cmd/gopcomm/community_yap.gox:550:1 refererPath := refererURL.Path -//line cmd/gopcomm/community_yap.gox:528:1 +//line cmd/gopcomm/community_yap.gox:551:1 if refererURL.RawQuery != "" { -//line cmd/gopcomm/community_yap.gox:529:1 +//line cmd/gopcomm/community_yap.gox:552:1 refererPath = fmt.Sprintf("%s?%s", refererURL.Path, refererURL.RawQuery) } -//line cmd/gopcomm/community_yap.gox:532:1 +//line cmd/gopcomm/community_yap.gox:555:1 http.Redirect(ctx.ResponseWriter, ctx.Request, refererPath, http.StatusFound) }) -//line cmd/gopcomm/community_yap.gox:535:1 +//line cmd/gopcomm/community_yap.gox:558:1 this.Get("/callback", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:536:1 +//line cmd/gopcomm/community_yap.gox:559:1 err := core.SetToken(ctx) -//line cmd/gopcomm/community_yap.gox:537:1 +//line cmd/gopcomm/community_yap.gox:560:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:538:1 +//line cmd/gopcomm/community_yap.gox:561:1 xLog.Error("set token error:", err) } -//line cmd/gopcomm/community_yap.gox:540:1 +//line cmd/gopcomm/community_yap.gox:563:1 origin_path := ctx.URL.Query().Get("origin_path") -//line cmd/gopcomm/community_yap.gox:541:1 +//line cmd/gopcomm/community_yap.gox:564:1 unurl, err := url.QueryUnescape(origin_path) -//line cmd/gopcomm/community_yap.gox:542:1 +//line cmd/gopcomm/community_yap.gox:565:1 if err != nil { -//line cmd/gopcomm/community_yap.gox:543:1 +//line cmd/gopcomm/community_yap.gox:566:1 xLog.Info("Unurl error", err) -//line cmd/gopcomm/community_yap.gox:544:1 +//line cmd/gopcomm/community_yap.gox:567:1 unurl = "/" } -//line cmd/gopcomm/community_yap.gox:547:1 +//line cmd/gopcomm/community_yap.gox:570:1 http.Redirect(ctx.ResponseWriter, ctx.Request, unurl, http.StatusFound) }) -//line cmd/gopcomm/community_yap.gox:550:1 +//line cmd/gopcomm/community_yap.gox:573:1 conf := &core.Config{} -//line cmd/gopcomm/community_yap.gox:551:1 +//line cmd/gopcomm/community_yap.gox:574:1 this.community, _ = core.New(todo, conf) -//line cmd/gopcomm/community_yap.gox:552:1 +//line cmd/gopcomm/community_yap.gox:575:1 core.CasdoorConfigInit() -//line cmd/gopcomm/community_yap.gox:555:1 +//line cmd/gopcomm/community_yap.gox:578:1 this.Handle("/", func(ctx *yap.Context) { -//line cmd/gopcomm/community_yap.gox:556:1 +//line cmd/gopcomm/community_yap.gox:579:1 ctx.Yap__1("4xx", map[string]interface { }{}) }) -//line cmd/gopcomm/community_yap.gox:559:1 +//line cmd/gopcomm/community_yap.gox:582:1 xLog.Info("Started in endpoint: ", endpoint) -//line cmd/gopcomm/community_yap.gox:562:1 +//line cmd/gopcomm/community_yap.gox:585:1 this.Run(endpoint, func(h http.Handler) http.Handler { -//line cmd/gopcomm/community_yap.gox:564:1 +//line cmd/gopcomm/community_yap.gox:587:1 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { -//line cmd/gopcomm/community_yap.gox:565:1 +//line cmd/gopcomm/community_yap.gox:588:1 defer func() { -//line cmd/gopcomm/community_yap.gox:566:1 +//line cmd/gopcomm/community_yap.gox:589:1 if -//line cmd/gopcomm/community_yap.gox:566:1 +//line cmd/gopcomm/community_yap.gox:589:1 err := recover(); err != nil { -//line cmd/gopcomm/community_yap.gox:567:1 +//line cmd/gopcomm/community_yap.gox:590:1 http.Redirect(w, r, "/failed", http.StatusFound) } }() -//line cmd/gopcomm/community_yap.gox:571:1 +//line cmd/gopcomm/community_yap.gox:594:1 h.ServeHTTP(w, r) }) }) } func main() { +//line cmd/gopcomm/community_yap.gox:585:1 yap.Gopt_App_Main(new(community)) } diff --git a/cmd/gopcomm/yap/static/js/user_edit.js b/cmd/gopcomm/yap/static/js/user_edit.js index 1ba9587f..1ecf171c 100644 --- a/cmd/gopcomm/yap/static/js/user_edit.js +++ b/cmd/gopcomm/yap/static/js/user_edit.js @@ -1,1209 +1,647 @@ const authInfo = { - Google: { - scope: "profile+email", - endpoint: "https://accounts.google.com/signin/oauth", - }, - GitHub: { - scope: "user:email+read:user", - endpoint: "https://github.com/login/oauth/authorize", - }, - QQ: { - scope: "get_user_info", - endpoint: "https://graph.qq.com/oauth2.0/authorize", - }, - WeChat: { - scope: "snsapi_login", - endpoint: "https://open.weixin.qq.com/connect/qrconnect", - mpScope: "snsapi_userinfo", - mpEndpoint: "https://open.weixin.qq.com/connect/oauth2/authorize", - }, - WeChatMiniProgram: { - endpoint: "https://mp.weixin.qq.com/", - }, - Facebook: { - scope: "email,public_profile", - endpoint: "https://www.facebook.com/dialog/oauth", - }, - DingTalk: { - scope: "openid", - endpoint: "https://login.dingtalk.com/oauth2/auth", - }, - Weibo: { - scope: "email", - endpoint: "https://api.weibo.com/oauth2/authorize", - }, - Gitee: { - scope: "user_info%20emails", - endpoint: "https://gitee.com/oauth/authorize", - }, - LinkedIn: { - scope: "r_liteprofile%20r_emailaddress", - endpoint: "https://www.linkedin.com/oauth/v2/authorization", - }, - WeCom: { - scope: "snsapi_userinfo", - endpoint: "https://open.work.weixin.qq.com/wwopen/sso/3rd_qrConnect", - silentEndpoint: "https://open.weixin.qq.com/connect/oauth2/authorize", - internalEndpoint: "https://open.work.weixin.qq.com/wwopen/sso/qrConnect", - }, - Lark: { - // scope: "email", - endpoint: "https://open.feishu.cn/open-apis/authen/v1/index", - }, - GitLab: { - scope: "read_user+profile", - endpoint: "https://gitlab.com/oauth/authorize", - }, - ADFS: { - scope: "openid", - endpoint: "http://example.com", - }, - Baidu: { - scope: "basic", - endpoint: "http://openapi.baidu.com/oauth/2.0/authorize", - }, - Alipay: { - scope: "basic", - endpoint: "https://openauth.alipay.com/oauth2/publicAppAuthorize.htm", - }, - Casdoor: { - scope: "openid%20profile%20email", - endpoint: "http://example.com", - }, - Infoflow: { - endpoint: "https://xpc.im.baidu.com/oauth2/authorize", - }, - Apple: { - scope: "name%20email", - endpoint: "https://appleid.apple.com/auth/authorize", - }, - AzureAD: { - scope: "user.read", - endpoint: "https://login.microsoftonline.com/common/oauth2/v2.0/authorize", - }, - AzureADB2C: { - scope: "openid", - endpoint: "https://tenant.b2clogin.com/tenant.onmicrosoft.com/userflow/oauth2/v2.0/authorize", - }, - Slack: { - scope: "users:read", - endpoint: "https://slack.com/oauth/authorize", - }, - Steam: { - endpoint: "https://steamcommunity.com/openid/login", - }, - Okta: { - scope: "openid%20profile%20email", - endpoint: "http://example.com", - }, - Douyin: { - scope: "user_info", - endpoint: "https://open.douyin.com/platform/oauth/connect", - }, - Custom: { - endpoint: "https://example.com/", - }, - Bilibili: { - endpoint: "https://passport.bilibili.com/register/pc_oauth2.html", - }, - Line: { - scope: "profile%20openid%20email", - endpoint: "https://access.line.me/oauth2/v2.1/authorize", - }, - Amazon: { - scope: "profile", - endpoint: "https://www.amazon.com/ap/oa", - }, - Auth0: { - scope: "openid%20profile%20email", - endpoint: "http://auth0.com/authorize", - }, - BattleNet: { - scope: "openid", - endpoint: "https://oauth.battlenet.com.cn/authorize", - }, - Bitbucket: { - scope: "account", - endpoint: "https://bitbucket.org/site/oauth2/authorize", - }, - Box: { - scope: "root_readwrite", - endpoint: "https://account.box.com/api/oauth2/authorize", - }, - CloudFoundry: { - scope: "cloud_controller.read", - endpoint: "https://login.cloudfoundry.org/oauth/authorize", - }, - Dailymotion: { - scope: "userinfo", - endpoint: "https://api.dailymotion.com/oauth/authorize", - }, - Deezer: { - scope: "basic_access", - endpoint: "https://connect.deezer.com/oauth/auth.php", - }, - DigitalOcean: { - scope: "read", - endpoint: "https://cloud.digitalocean.com/v1/oauth/authorize", - }, - Discord: { - scope: "identify%20email", - endpoint: "https://discord.com/api/oauth2/authorize", - }, - Dropbox: { - scope: "account_info.read", - endpoint: "https://www.dropbox.com/oauth2/authorize", - }, - EveOnline: { - scope: "publicData", - endpoint: "https://login.eveonline.com/oauth/authorize", - }, - Fitbit: { - scope: "activity%20heartrate%20location%20nutrition%20profile%20settings%20sleep%20social%20weight", - endpoint: "https://www.fitbit.com/oauth2/authorize", - }, - Gitea: { - scope: "user:email", - endpoint: "https://gitea.com/login/oauth/authorize", - }, - Heroku: { - scope: "global", - endpoint: "https://id.heroku.com/oauth/authorize", - }, - InfluxCloud: { - scope: "read:org", - endpoint: "https://cloud2.influxdata.com/oauth/authorize", - }, - Instagram: { - scope: "user_profile", - endpoint: "https://api.instagram.com/oauth/authorize", - }, - Intercom: { - scope: "user.read", - endpoint: "https://app.intercom.com/oauth", - }, - Kakao: { - scope: "account_email", - endpoint: "https://kauth.kakao.com/oauth/authorize", - }, - Lastfm: { - scope: "user_read", - endpoint: "https://www.last.fm/api/auth", - }, - Mailru: { - scope: "userinfo", - endpoint: "https://oauth.mail.ru/login", - }, - Meetup: { - scope: "basic", - endpoint: "https://secure.meetup.com/oauth2/authorize", - }, - MicrosoftOnline: { - scope: "openid%20profile%20email", - endpoint: "https://login.microsoftonline.com/common/oauth2/v2.0/authorize", - }, - Naver: { - scope: "profile", - endpoint: "https://nid.naver.com/oauth2.0/authorize", - }, - Nextcloud: { - scope: "openid%20profile%20email", - endpoint: "https://cloud.example.org/apps/oauth2/authorize", - }, - OneDrive: { - scope: "offline_access%20onedrive.readonly", - endpoint: "https://login.live.com/oauth20_authorize.srf", - }, - Oura: { - scope: "personal", - endpoint: "https://cloud.ouraring.com/oauth/authorize", - }, - Patreon: { - scope: "identity", - endpoint: "https://www.patreon.com/oauth2/authorize", - }, - PayPal: { - scope: "openid%20profile%20email", - endpoint: "https://www.sandbox.paypal.com/connect", - }, - SalesForce: { - scope: "openid%20profile%20email", - endpoint: "https://login.salesforce.com/services/oauth2/authorize", - }, - Shopify: { - scope: "read_products", - endpoint: "https://myshopify.com/admin/oauth/authorize", - }, - Soundcloud: { - scope: "non-expiring", - endpoint: "https://api.soundcloud.com/connect", - }, - Spotify: { - scope: "user-read-email", - endpoint: "https://accounts.spotify.com/authorize", - }, - Strava: { - scope: "read", - endpoint: "https://www.strava.com/oauth/authorize", - }, - Stripe: { - scope: "read_only", - endpoint: "https://connect.stripe.com/oauth/authorize", - }, - TikTok: { - scope: "user.info.basic", - endpoint: "https://www.tiktok.com/auth/authorize/", - }, - Tumblr: { - scope: "email", - endpoint: "https://www.tumblr.com/oauth2/authorize", - }, - Twitch: { - scope: "user_read", - endpoint: "https://id.twitch.tv/oauth2/authorize", - }, - Twitter: { - scope: "users.read%20tweet.read", - endpoint: "https://twitter.com/i/oauth2/authorize", - }, - Typetalk: { - scope: "my", - endpoint: "https://typetalk.com/oauth2/authorize", - }, - Uber: { - scope: "profile", - endpoint: "https://login.uber.com/oauth/v2/authorize", - }, - VK: { - scope: "email", - endpoint: "https://oauth.vk.com/authorize", - }, - Wepay: { - scope: "manage_accounts%20view_user", - endpoint: "https://www.wepay.com/v2/oauth2/authorize", - }, - Xero: { - scope: "openid%20profile%20email", - endpoint: "https://login.xero.com/identity/connect/authorize", - }, - Yahoo: { - scope: "openid%20profile%20email", - endpoint: "https://api.login.yahoo.com/oauth2/request_auth", - }, - Yammer: { - scope: "user", - endpoint: "https://www.yammer.com/oauth2/authorize", - }, - Yandex: { - scope: "login:email", - endpoint: "https://oauth.yandex.com/authorize", - }, - Zoom: { - scope: "user:read", - endpoint: "https://zoom.us/oauth/authorize", - }, - MetaMask: { - scope: "", - endpoint: "", - }, - Web3Onboard: { - scope: "", - endpoint: "", - }, - }; + Google: { + scope: "profile+email", + endpoint: "https://accounts.google.com/signin/oauth", + }, + GitHub: { + scope: "user:email+read:user", + endpoint: "https://github.com/login/oauth/authorize", + }, + QQ: { + scope: "get_user_info", + endpoint: "https://graph.qq.com/oauth2.0/authorize", + }, + WeChat: { + scope: "snsapi_login", + endpoint: "https://open.weixin.qq.com/connect/qrconnect", + mpScope: "snsapi_userinfo", + mpEndpoint: "https://open.weixin.qq.com/connect/oauth2/authorize", + }, + WeChatMiniProgram: { + endpoint: "https://mp.weixin.qq.com/", + }, + Facebook: { + scope: "email,public_profile", + endpoint: "https://www.facebook.com/dialog/oauth", + }, + DingTalk: { + scope: "openid", + endpoint: "https://login.dingtalk.com/oauth2/auth", + }, + Weibo: { + scope: "email", + endpoint: "https://api.weibo.com/oauth2/authorize", + }, + Gitee: { + scope: "user_info%20emails", + endpoint: "https://gitee.com/oauth/authorize", + }, + LinkedIn: { + scope: "r_liteprofile%20r_emailaddress", + endpoint: "https://www.linkedin.com/oauth/v2/authorization", + }, + WeCom: { + scope: "snsapi_userinfo", + endpoint: "https://open.work.weixin.qq.com/wwopen/sso/3rd_qrConnect", + silentEndpoint: "https://open.weixin.qq.com/connect/oauth2/authorize", + internalEndpoint: "https://open.work.weixin.qq.com/wwopen/sso/qrConnect", + }, + Lark: { + // scope: "email", + endpoint: "https://open.feishu.cn/open-apis/authen/v1/index", + }, + GitLab: { + scope: "read_user+profile", + endpoint: "https://gitlab.com/oauth/authorize", + }, + ADFS: { + scope: "openid", + endpoint: "http://example.com", + }, + Baidu: { + scope: "basic", + endpoint: "http://openapi.baidu.com/oauth/2.0/authorize", + }, + Alipay: { + scope: "basic", + endpoint: "https://openauth.alipay.com/oauth2/publicAppAuthorize.htm", + }, + Casdoor: { + scope: "openid%20profile%20email", + endpoint: "http://example.com", + }, + Infoflow: { + endpoint: "https://xpc.im.baidu.com/oauth2/authorize", + }, + Apple: { + scope: "name%20email", + endpoint: "https://appleid.apple.com/auth/authorize", + }, + AzureAD: { + scope: "user.read", + endpoint: "https://login.microsoftonline.com/common/oauth2/v2.0/authorize", + }, + AzureADB2C: { + scope: "openid", + endpoint: "https://tenant.b2clogin.com/tenant.onmicrosoft.com/userflow/oauth2/v2.0/authorize", + }, + Slack: { + scope: "users:read", + endpoint: "https://slack.com/oauth/authorize", + }, + Steam: { + endpoint: "https://steamcommunity.com/openid/login", + }, + Okta: { + scope: "openid%20profile%20email", + endpoint: "http://example.com", + }, + Douyin: { + scope: "user_info", + endpoint: "https://open.douyin.com/platform/oauth/connect", + }, + Custom: { + endpoint: "https://example.com/", + }, + Bilibili: { + endpoint: "https://passport.bilibili.com/register/pc_oauth2.html", + }, + Line: { + scope: "profile%20openid%20email", + endpoint: "https://access.line.me/oauth2/v2.1/authorize", + }, + Amazon: { + scope: "profile", + endpoint: "https://www.amazon.com/ap/oa", + }, + Auth0: { + scope: "openid%20profile%20email", + endpoint: "http://auth0.com/authorize", + }, + BattleNet: { + scope: "openid", + endpoint: "https://oauth.battlenet.com.cn/authorize", + }, + Bitbucket: { + scope: "account", + endpoint: "https://bitbucket.org/site/oauth2/authorize", + }, + Box: { + scope: "root_readwrite", + endpoint: "https://account.box.com/api/oauth2/authorize", + }, + CloudFoundry: { + scope: "cloud_controller.read", + endpoint: "https://login.cloudfoundry.org/oauth/authorize", + }, + Dailymotion: { + scope: "userinfo", + endpoint: "https://api.dailymotion.com/oauth/authorize", + }, + Deezer: { + scope: "basic_access", + endpoint: "https://connect.deezer.com/oauth/auth.php", + }, + DigitalOcean: { + scope: "read", + endpoint: "https://cloud.digitalocean.com/v1/oauth/authorize", + }, + Discord: { + scope: "identify%20email", + endpoint: "https://discord.com/api/oauth2/authorize", + }, + Dropbox: { + scope: "account_info.read", + endpoint: "https://www.dropbox.com/oauth2/authorize", + }, + EveOnline: { + scope: "publicData", + endpoint: "https://login.eveonline.com/oauth/authorize", + }, + Fitbit: { + scope: "activity%20heartrate%20location%20nutrition%20profile%20settings%20sleep%20social%20weight", + endpoint: "https://www.fitbit.com/oauth2/authorize", + }, + Gitea: { + scope: "user:email", + endpoint: "https://gitea.com/login/oauth/authorize", + }, + Heroku: { + scope: "global", + endpoint: "https://id.heroku.com/oauth/authorize", + }, + InfluxCloud: { + scope: "read:org", + endpoint: "https://cloud2.influxdata.com/oauth/authorize", + }, + Instagram: { + scope: "user_profile", + endpoint: "https://api.instagram.com/oauth/authorize", + }, + Intercom: { + scope: "user.read", + endpoint: "https://app.intercom.com/oauth", + }, + Kakao: { + scope: "account_email", + endpoint: "https://kauth.kakao.com/oauth/authorize", + }, + Lastfm: { + scope: "user_read", + endpoint: "https://www.last.fm/api/auth", + }, + Mailru: { + scope: "userinfo", + endpoint: "https://oauth.mail.ru/login", + }, + Meetup: { + scope: "basic", + endpoint: "https://secure.meetup.com/oauth2/authorize", + }, + MicrosoftOnline: { + scope: "openid%20profile%20email", + endpoint: "https://login.microsoftonline.com/common/oauth2/v2.0/authorize", + }, + Naver: { + scope: "profile", + endpoint: "https://nid.naver.com/oauth2.0/authorize", + }, + Nextcloud: { + scope: "openid%20profile%20email", + endpoint: "https://cloud.example.org/apps/oauth2/authorize", + }, + OneDrive: { + scope: "offline_access%20onedrive.readonly", + endpoint: "https://login.live.com/oauth20_authorize.srf", + }, + Oura: { + scope: "personal", + endpoint: "https://cloud.ouraring.com/oauth/authorize", + }, + Patreon: { + scope: "identity", + endpoint: "https://www.patreon.com/oauth2/authorize", + }, + PayPal: { + scope: "openid%20profile%20email", + endpoint: "https://www.sandbox.paypal.com/connect", + }, + SalesForce: { + scope: "openid%20profile%20email", + endpoint: "https://login.salesforce.com/services/oauth2/authorize", + }, + Shopify: { + scope: "read_products", + endpoint: "https://myshopify.com/admin/oauth/authorize", + }, + Soundcloud: { + scope: "non-expiring", + endpoint: "https://api.soundcloud.com/connect", + }, + Spotify: { + scope: "user-read-email", + endpoint: "https://accounts.spotify.com/authorize", + }, + Strava: { + scope: "read", + endpoint: "https://www.strava.com/oauth/authorize", + }, + Stripe: { + scope: "read_only", + endpoint: "https://connect.stripe.com/oauth/authorize", + }, + TikTok: { + scope: "user.info.basic", + endpoint: "https://www.tiktok.com/auth/authorize/", + }, + Tumblr: { + scope: "email", + endpoint: "https://www.tumblr.com/oauth2/authorize", + }, + Twitch: { + scope: "user_read", + endpoint: "https://id.twitch.tv/oauth2/authorize", + }, + Twitter: { + scope: "users.read%20tweet.read", + endpoint: "https://twitter.com/i/oauth2/authorize", + }, + Typetalk: { + scope: "my", + endpoint: "https://typetalk.com/oauth2/authorize", + }, + Uber: { + scope: "profile", + endpoint: "https://login.uber.com/oauth/v2/authorize", + }, + VK: { + scope: "email", + endpoint: "https://oauth.vk.com/authorize", + }, + Wepay: { + scope: "manage_accounts%20view_user", + endpoint: "https://www.wepay.com/v2/oauth2/authorize", + }, + Xero: { + scope: "openid%20profile%20email", + endpoint: "https://login.xero.com/identity/connect/authorize", + }, + Yahoo: { + scope: "openid%20profile%20email", + endpoint: "https://api.login.yahoo.com/oauth2/request_auth", + }, + Yammer: { + scope: "user", + endpoint: "https://www.yammer.com/oauth2/authorize", + }, + Yandex: { + scope: "login:email", + endpoint: "https://oauth.yandex.com/authorize", + }, + Zoom: { + scope: "user:read", + endpoint: "https://zoom.us/oauth/authorize", + }, + MetaMask: { + scope: "", + endpoint: "", + }, + Web3Onboard: { + scope: "", + endpoint: "", + }, +}; - const providers = [ - { - "owner": "admin", - "name": "provider_github", - "createdTime": "2024-01-22T11:15:22+08:00", - "displayName": "New Provider - github", - "category": "OAuth", - "type": "GitHub", - "subType": "", - "method": "Normal", - "clientId": "Iv1.de7a592b6cc33131", - "clientSecret": "***", - "clientId2": "", - "clientSecret2": "", - "cert": "", - "customAuthUrl": "", - "customTokenUrl": "", - "customUserInfoUrl": "", - "customLogo": "", - "scopes": "", - "userMapping": {}, - "host": "", - "port": 0, - "disableSsl": false, - "title": "", - "content": "", - "receiver": "", - "regionId": "", - "signName": "", - "templateCode": "", - "appId": "", - "endpoint": "", - "intranetEndpoint": "", - "domain": "", - "bucket": "", - "pathPrefix": "", - "metadata": "", - "idP": "", - "issuerUrl": "", - "enableSignAuthnRequest": false, - "providerUrl": "https://github.com/organizations/xxx/settings/applications/1234567" - }, - { - "owner": "admin", - "name": "provider_twitter", - "createdTime": "2024-01-22T11:20:19+08:00", - "displayName": "New Provider - twitter", - "category": "OAuth", - "type": "Twitter", - "subType": "", - "method": "Normal", - "clientId": "VmNJS2otVTlZYUVLNEVVZ0ZJc2w6MTpjaQ", - "clientSecret": "***", - "clientId2": "", - "clientSecret2": "", - "cert": "", - "customAuthUrl": "", - "customTokenUrl": "", - "customUserInfoUrl": "", - "customLogo": "", - "scopes": "", - "userMapping": {}, - "host": "", - "port": 0, - "disableSsl": false, - "title": "", - "content": "", - "receiver": "", - "regionId": "", - "signName": "", - "templateCode": "", - "appId": "", - "endpoint": "", - "intranetEndpoint": "", - "domain": "", - "bucket": "", - "pathPrefix": "", - "metadata": "", - "idP": "", - "issuerUrl": "", - "enableSignAuthnRequest": false, - "providerUrl": "https://github.com/organizations/xxx/settings/applications/1234567" - }, - { - "owner": "admin", - "name": "provider_facebook", - "createdTime": "2024-01-22T11:19:03+08:00", - "displayName": "New Provider - facebook", - "category": "OAuth", - "type": "Facebook", - "subType": "", - "method": "Normal", - "clientId": "927083362474156", - "clientSecret": "***", - "clientId2": "", - "clientSecret2": "", - "cert": "", - "customAuthUrl": "", - "customTokenUrl": "", - "customUserInfoUrl": "", - "customLogo": "", - "scopes": "", - "userMapping": {}, - "host": "", - "port": 0, - "disableSsl": false, - "title": "", - "content": "", - "receiver": "", - "regionId": "", - "signName": "", - "templateCode": "", - "appId": "", - "endpoint": "", - "intranetEndpoint": "", - "domain": "", - "bucket": "", - "pathPrefix": "", - "metadata": "", - "idP": "", - "issuerUrl": "", - "enableSignAuthnRequest": false, - "providerUrl": "https://github.com/organizations/xxx/settings/applications/1234567" - }, - { - "owner": "admin", - "name": "provider_wechat", - "createdTime": "2024-01-25T10:20:42+08:00", - "displayName": "wechat", - "category": "OAuth", - "type": "WeChat", - "subType": "", - "method": "Normal", - "clientId": "wxf6fad0f92d9e8313", - "clientSecret": "***", - "clientId2": "wxf6fad0f92d9e8313", - "clientSecret2": "***", - "cert": "", - "customAuthUrl": "", - "customTokenUrl": "", - "customUserInfoUrl": "", - "customLogo": "", - "scopes": "", - "userMapping": {}, - "host": "", - "port": 0, - "disableSsl": true, - "title": "", - "content": "iVBORw0KGgoAAAANSUhEUgAAAQAAAAEAAQMAAABmvDolAAAABlBMVEX///8AAABVwtN+AAAB+ElEQVR42uyYPfLrIAzE10NByRE4Cjfzx804CkegpGC8byQ8SZyX6l9ZHquK418jI1Yr4YknnvhbLCTZAFbMAMiy9CD/8V4AgKkhsWJiTY5l6iEfL+wAjtxazI5laZrmjJAlW4MA+8i2ezksq4AeDytcA3BHQGsyZlZ5Sh1xx4+ivTqg+hBzD2X2NbkWt18CcnFgRCQUGDfrR1wckJLjULkZgR2Rmma5FwDWtHrS1ShHKDXpmKf3zTIBLK4eNyuyhexaXF3F7rnaApjhC0iuCHQNU9fOBFtAxSK9KBTR6nFgSWzPvQAErohkjVsLlE8i8v7p5WwAeRH/IGlSzJBYOiCulgA4cvcFesEAeK5DH2AKQJDHpJUXCD23tPu3DN4GmD2lD+3aebkjcOJLBm0AfJ2dyIQOQfgUcxPA0rUQs9o3TXNTMX/rgwnA1bSRuYvY6RA0j0u23A7YMfyDDEGjJZ3mbguA6MMoxvmV5rfaXx9wYqjFjeoQJPrgaprOLsgCkIazEcHTJYJAJ8t6A+Bj1hP/wKaScmpJBoBjeZi6/pTxgT3kz+9gAjh2IB3qSDv+S9MEcOyjBBgqt43EbwloTbah4pS7ViwC+chP5m4Efq16rg+MrbtqhKTpxcuJr7YFHMtDnUKrcjJW80tArANPPPHEOf4FAAD//zp6rk3/kINSAAAAAElFTkSuQmCC", - "receiver": "", - "regionId": "", - "signName": "", - "templateCode": "", - "appId": "", - "endpoint": "", - "intranetEndpoint": "", - "domain": "", - "bucket": "", - "pathPrefix": "", - "metadata": "", - "idP": "", - "issuerUrl": "", - "enableSignAuthnRequest": false, - "providerUrl": "https://open.weixin.qq.com/connect/oauth2/authorize" - } - ] +const providers = [ + { + "owner": "admin", + "name": "provider_github", + "createdTime": "2024-01-22T11:15:22+08:00", + "displayName": "New Provider - github", + "category": "OAuth", + "type": "GitHub", + "subType": "", + "method": "Normal", + "clientId": "Iv1.de7a592b6cc33131", + "clientSecret": "***", + "clientId2": "", + "clientSecret2": "", + "cert": "", + "customAuthUrl": "", + "customTokenUrl": "", + "customUserInfoUrl": "", + "customLogo": "", + "scopes": "", + "userMapping": {}, + "host": "", + "port": 0, + "disableSsl": false, + "title": "", + "content": "", + "receiver": "", + "regionId": "", + "signName": "", + "templateCode": "", + "appId": "", + "endpoint": "", + "intranetEndpoint": "", + "domain": "", + "bucket": "", + "pathPrefix": "", + "metadata": "", + "idP": "", + "issuerUrl": "", + "enableSignAuthnRequest": false, + "providerUrl": "https://github.com/organizations/xxx/settings/applications/1234567" + }, + { + "owner": "admin", + "name": "provider_twitter", + "createdTime": "2024-01-22T11:20:19+08:00", + "displayName": "New Provider - twitter", + "category": "OAuth", + "type": "Twitter", + "subType": "", + "method": "Normal", + "clientId": "VmNJS2otVTlZYUVLNEVVZ0ZJc2w6MTpjaQ", + "clientSecret": "***", + "clientId2": "", + "clientSecret2": "", + "cert": "", + "customAuthUrl": "", + "customTokenUrl": "", + "customUserInfoUrl": "", + "customLogo": "", + "scopes": "", + "userMapping": {}, + "host": "", + "port": 0, + "disableSsl": false, + "title": "", + "content": "", + "receiver": "", + "regionId": "", + "signName": "", + "templateCode": "", + "appId": "", + "endpoint": "", + "intranetEndpoint": "", + "domain": "", + "bucket": "", + "pathPrefix": "", + "metadata": "", + "idP": "", + "issuerUrl": "", + "enableSignAuthnRequest": false, + "providerUrl": "https://github.com/organizations/xxx/settings/applications/1234567" + }, + { + "owner": "admin", + "name": "provider_facebook", + "createdTime": "2024-01-22T11:19:03+08:00", + "displayName": "New Provider - facebook", + "category": "OAuth", + "type": "Facebook", + "subType": "", + "method": "Normal", + "clientId": "927083362474156", + "clientSecret": "***", + "clientId2": "", + "clientSecret2": "", + "cert": "", + "customAuthUrl": "", + "customTokenUrl": "", + "customUserInfoUrl": "", + "customLogo": "", + "scopes": "", + "userMapping": {}, + "host": "", + "port": 0, + "disableSsl": false, + "title": "", + "content": "", + "receiver": "", + "regionId": "", + "signName": "", + "templateCode": "", + "appId": "", + "endpoint": "", + "intranetEndpoint": "", + "domain": "", + "bucket": "", + "pathPrefix": "", + "metadata": "", + "idP": "", + "issuerUrl": "", + "enableSignAuthnRequest": false, + "providerUrl": "https://github.com/organizations/xxx/settings/applications/1234567" + }, + { + "owner": "admin", + "name": "provider_wechat", + "createdTime": "2024-01-25T10:20:42+08:00", + "displayName": "wechat", + "category": "OAuth", + "type": "WeChat", + "subType": "", + "method": "Normal", + "clientId": "wxf6fad0f92d9e8313", + "clientSecret": "***", + "clientId2": "wxf6fad0f92d9e8313", + "clientSecret2": "***", + "cert": "", + "customAuthUrl": "", + "customTokenUrl": "", + "customUserInfoUrl": "", + "customLogo": "", + "scopes": "", + "userMapping": {}, + "host": "", + "port": 0, + "disableSsl": true, + "title": "", + "content": "iVBORw0KGgoAAAANSUhEUgAAAQAAAAEAAQMAAABmvDolAAAABlBMVEX///8AAABVwtN+AAAB+ElEQVR42uyYPfLrIAzE10NByRE4Cjfzx804CkegpGC8byQ8SZyX6l9ZHquK418jI1Yr4YknnvhbLCTZAFbMAMiy9CD/8V4AgKkhsWJiTY5l6iEfL+wAjtxazI5laZrmjJAlW4MA+8i2ezksq4AeDytcA3BHQGsyZlZ5Sh1xx4+ivTqg+hBzD2X2NbkWt18CcnFgRCQUGDfrR1wckJLjULkZgR2Rmma5FwDWtHrS1ShHKDXpmKf3zTIBLK4eNyuyhexaXF3F7rnaApjhC0iuCHQNU9fOBFtAxSK9KBTR6nFgSWzPvQAErohkjVsLlE8i8v7p5WwAeRH/IGlSzJBYOiCulgA4cvcFesEAeK5DH2AKQJDHpJUXCD23tPu3DN4GmD2lD+3aebkjcOJLBm0AfJ2dyIQOQfgUcxPA0rUQs9o3TXNTMX/rgwnA1bSRuYvY6RA0j0u23A7YMfyDDEGjJZ3mbguA6MMoxvmV5rfaXx9wYqjFjeoQJPrgaprOLsgCkIazEcHTJYJAJ8t6A+Bj1hP/wKaScmpJBoBjeZi6/pTxgT3kz+9gAjh2IB3qSDv+S9MEcOyjBBgqt43EbwloTbah4pS7ViwC+chP5m4Efq16rg+MrbtqhKTpxcuJr7YFHMtDnUKrcjJW80tArANPPPHEOf4FAAD//zp6rk3/kINSAAAAAElFTkSuQmCC", + "receiver": "", + "regionId": "", + "signName": "", + "templateCode": "", + "appId": "", + "endpoint": "", + "intranetEndpoint": "", + "domain": "", + "bucket": "", + "pathPrefix": "", + "metadata": "", + "idP": "", + "issuerUrl": "", + "enableSignAuthnRequest": false, + "providerUrl": "https://open.weixin.qq.com/connect/oauth2/authorize" + } +] function getStateFromQueryParams(applicationName, providerName, method, isShortState) { - let query = window.location.search; - query = `${query}&application=${encodeURIComponent(applicationName)}&provider=${encodeURIComponent(providerName)}&method=${method}`; - if (method === "link") { - query = `${query}&from=${window.location.pathname}`; - } - - if (!isShortState) { - return btoa(query); - } else { - const state = providerName; - sessionStorage.setItem(state, query); - return state; - } + let query = window.location.search; + query = `${query}&application=${encodeURIComponent(applicationName)}&provider=${encodeURIComponent(providerName)}&method=${method}`; + if (method === "link") { + query = `${query}&from=${window.location.href}`; + } + + if (!isShortState) { + return btoa(query); + } else { + const state = providerName; + sessionStorage.setItem(state, query); + return state; } +} function getAuthUrl(provider, method, res) { - application = { - "owner": "admin", - "name": "application_x8aevk", - "createdTime": "2024-01-22T11:12:21+08:00", - "displayName": "New Application - x8aevk", - "logo": "https://img0.baidu.com/it/u=1037925000,2019845499&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500", - "homepageUrl": "", - "description": "", - "organization": "built-in", - "cert": "cert-built-in", - "enablePassword": true, - "enableSignUp": true, - "enableSigninSession": false, - "enableAutoSignin": false, - "enableCodeSignin": false, - "enableSamlCompress": false, - "enableSamlC14n10": false, - "enableSamlPostBinding": false, - "enableWebAuthn": false, - "enableLinkWithEmail": true, - "orgChoiceMode": "", - "samlReplyUrl": "", - "providers": [ - { - "owner": "", - "name": "provider_github", - "canSignUp": true, - "canSignIn": true, - "canUnlink": true, - "prompted": false, - "signupGroup": "", - "rule": "None", - "provider": { - "owner": "admin", - "name": "provider_github", - "createdTime": "2024-01-22T11:15:22+08:00", - "displayName": "New Provider - github", - "category": "OAuth", - "type": "GitHub", - "subType": "", - "method": "Normal", - "clientId": "Iv1.de7a592b6cc33131", - "clientSecret": "***", - "clientId2": "", - "clientSecret2": "", - "cert": "", - "customAuthUrl": "", - "customTokenUrl": "", - "customUserInfoUrl": "", - "customLogo": "", - "scopes": "", - "userMapping": {}, - "host": "", - "port": 0, - "disableSsl": false, - "title": "", - "content": "", - "receiver": "", - "regionId": "", - "signName": "", - "templateCode": "", - "appId": "", - "endpoint": "", - "intranetEndpoint": "", - "domain": "", - "bucket": "", - "pathPrefix": "", - "metadata": "", - "idP": "", - "issuerUrl": "", - "enableSignAuthnRequest": false, - "providerUrl": "https://github.com/organizations/xxx/settings/applications/1234567" - } - }, - { - "owner": "", - "name": "provider_twitter", - "canSignUp": true, - "canSignIn": true, - "canUnlink": true, - "prompted": false, - "signupGroup": "", - "rule": "None", - "provider": { - "owner": "admin", - "name": "provider_twitter", - "createdTime": "2024-01-22T11:20:19+08:00", - "displayName": "New Provider - twitter", - "category": "OAuth", - "type": "Twitter", - "subType": "", - "method": "Normal", - "clientId": "VmNJS2otVTlZYUVLNEVVZ0ZJc2w6MTpjaQ", - "clientSecret": "***", - "clientId2": "", - "clientSecret2": "", - "cert": "", - "customAuthUrl": "", - "customTokenUrl": "", - "customUserInfoUrl": "", - "customLogo": "", - "scopes": "", - "userMapping": {}, - "host": "", - "port": 0, - "disableSsl": false, - "title": "", - "content": "", - "receiver": "", - "regionId": "", - "signName": "", - "templateCode": "", - "appId": "", - "endpoint": "", - "intranetEndpoint": "", - "domain": "", - "bucket": "", - "pathPrefix": "", - "metadata": "", - "idP": "", - "issuerUrl": "", - "enableSignAuthnRequest": false, - "providerUrl": "https://github.com/organizations/xxx/settings/applications/1234567" - } - }, - { - "owner": "", - "name": "provider_facebook", - "canSignUp": true, - "canSignIn": true, - "canUnlink": true, - "prompted": false, - "signupGroup": "", - "rule": "None", - "provider": { - "owner": "admin", - "name": "provider_facebook", - "createdTime": "2024-01-22T11:19:03+08:00", - "displayName": "New Provider - facebook", - "category": "OAuth", - "type": "Facebook", - "subType": "", - "method": "Normal", - "clientId": "927083362474156", - "clientSecret": "***", - "clientId2": "", - "clientSecret2": "", - "cert": "", - "customAuthUrl": "", - "customTokenUrl": "", - "customUserInfoUrl": "", - "customLogo": "", - "scopes": "", - "userMapping": {}, - "host": "", - "port": 0, - "disableSsl": false, - "title": "", - "content": "", - "receiver": "", - "regionId": "", - "signName": "", - "templateCode": "", - "appId": "", - "endpoint": "", - "intranetEndpoint": "", - "domain": "", - "bucket": "", - "pathPrefix": "", - "metadata": "", - "idP": "", - "issuerUrl": "", - "enableSignAuthnRequest": false, - "providerUrl": "https://github.com/organizations/xxx/settings/applications/1234567" - } - }, - { - "owner": "", - "name": "provider_wechat", - "canSignUp": true, - "canSignIn": true, - "canUnlink": true, - "prompted": false, - "signupGroup": "", - "rule": "None", - "provider": { - "owner": "admin", - "name": "provider_wechat", - "createdTime": "2024-01-25T10:20:42+08:00", - "displayName": "wechat", - "category": "OAuth", - "type": "WeChat", - "subType": "", - "method": "Normal", - "clientId": "wxf6fad0f92d9e8313", - "clientSecret": "***", - "clientId2": "wxf6fad0f92d9e8313", - "clientSecret2": "***", - "cert": "", - "customAuthUrl": "", - "customTokenUrl": "", - "customUserInfoUrl": "", - "customLogo": "", - "scopes": "", - "userMapping": {}, - "host": "", - "port": 0, - "disableSsl": true, - "title": "", - "content": "iVBORw0KGgoAAAANSUhEUgAAAQAAAAEAAQMAAABmvDolAAAABlBMVEX///8AAABVwtN+AAAB+ElEQVR42uyYPfLrIAzE10NByRE4Cjfzx804CkegpGC8byQ8SZyX6l9ZHquK418jI1Yr4YknnvhbLCTZAFbMAMiy9CD/8V4AgKkhsWJiTY5l6iEfL+wAjtxazI5laZrmjJAlW4MA+8i2ezksq4AeDytcA3BHQGsyZlZ5Sh1xx4+ivTqg+hBzD2X2NbkWt18CcnFgRCQUGDfrR1wckJLjULkZgR2Rmma5FwDWtHrS1ShHKDXpmKf3zTIBLK4eNyuyhexaXF3F7rnaApjhC0iuCHQNU9fOBFtAxSK9KBTR6nFgSWzPvQAErohkjVsLlE8i8v7p5WwAeRH/IGlSzJBYOiCulgA4cvcFesEAeK5DH2AKQJDHpJUXCD23tPu3DN4GmD2lD+3aebkjcOJLBm0AfJ2dyIQOQfgUcxPA0rUQs9o3TXNTMX/rgwnA1bSRuYvY6RA0j0u23A7YMfyDDEGjJZ3mbguA6MMoxvmV5rfaXx9wYqjFjeoQJPrgaprOLsgCkIazEcHTJYJAJ8t6A+Bj1hP/wKaScmpJBoBjeZi6/pTxgT3kz+9gAjh2IB3qSDv+S9MEcOyjBBgqt43EbwloTbah4pS7ViwC+chP5m4Efq16rg+MrbtqhKTpxcuJr7YFHMtDnUKrcjJW80tArANPPPHEOf4FAAD//zp6rk3/kINSAAAAAElFTkSuQmCC", - "receiver": "", - "regionId": "", - "signName": "", - "templateCode": "", - "appId": "", - "endpoint": "", - "intranetEndpoint": "", - "domain": "", - "bucket": "", - "pathPrefix": "", - "metadata": "", - "idP": "", - "issuerUrl": "", - "enableSignAuthnRequest": false, - "providerUrl": "https://open.weixin.qq.com/connect/oauth2/authorize" - } - } - ], - "signinMethods": [ - { - "name": "Password", - "displayName": "Password", - "rule": "All" - } - ], - "signupItems": [ - { - "name": "ID", - "visible": false, - "required": true, - "prompted": false, - "label": "", - "placeholder": "", - "regex": "", - "rule": "Random" - }, - { - "name": "Username", - "visible": true, - "required": true, - "prompted": false, - "label": "", - "placeholder": "", - "regex": "", - "rule": "None" - }, - { - "name": "Display name", - "visible": true, - "required": true, - "prompted": false, - "label": "", - "placeholder": "", - "regex": "", - "rule": "None" - }, - { - "name": "Password", - "visible": true, - "required": true, - "prompted": false, - "label": "", - "placeholder": "", - "regex": "", - "rule": "None" - }, - { - "name": "Confirm password", - "visible": true, - "required": true, - "prompted": false, - "label": "", - "placeholder": "", - "regex": "", - "rule": "None" - }, - { - "name": "Agreement", - "visible": true, - "required": true, - "prompted": false, - "label": "", - "placeholder": "", - "regex": "", - "rule": "None" - } - ], - "grantTypes": [ - "authorization_code" - ], - "organizationObj": { - "owner": "admin", - "name": "built-in", - "createdTime": "2024-01-22T01:27:18Z", - "displayName": "Built-in Organization", - "websiteUrl": "https://example.com", - "favicon": "https://cdn.casbin.org/img/casbin/favicon.ico", - "passwordType": "plain", - "passwordSalt": "", - "passwordOptions": [ - "AtLeast6" - ], - "countryCodes": [ - "US", - "ES", - "FR", - "DE", - "GB", - "CN", - "JP", - "KR", - "VN", - "ID", - "SG", - "IN" - ], - "defaultAvatar": "https://cdn.casbin.org/img/casbin.svg", - "defaultApplication": "", - "tags": [], - "languages": [ - "en", - "zh", - "es", - "fr", - "de", - "id", - "ja", - "ko", - "ru", - "vi", - "pt" - ], - "themeData": null, - "masterPassword": "", - "defaultPassword": "", - "masterVerificationCode": "", - "initScore": 2000, - "enableSoftDeletion": false, - "isProfilePublic": false, - "mfaItems": null, - "accountItems": [ - { - "name": "Organization", - "visible": true, - "viewRule": "Public", - "modifyRule": "Admin" - }, - { - "name": "ID", - "visible": true, - "viewRule": "Public", - "modifyRule": "Immutable" - }, - { - "name": "Name", - "visible": true, - "viewRule": "Public", - "modifyRule": "Admin" - }, - { - "name": "Display name", - "visible": true, - "viewRule": "Public", - "modifyRule": "Self" - }, - { - "name": "Avatar", - "visible": true, - "viewRule": "Public", - "modifyRule": "Self" - }, - { - "name": "User type", - "visible": true, - "viewRule": "Public", - "modifyRule": "Admin" - }, - { - "name": "Password", - "visible": true, - "viewRule": "Self", - "modifyRule": "Self" - }, - { - "name": "Email", - "visible": true, - "viewRule": "Public", - "modifyRule": "Self" - }, - { - "name": "Phone", - "visible": true, - "viewRule": "Public", - "modifyRule": "Self" - }, - { - "name": "Country code", - "visible": true, - "viewRule": "Public", - "modifyRule": "Admin" - }, - { - "name": "Country/Region", - "visible": true, - "viewRule": "Public", - "modifyRule": "Self" - }, - { - "name": "Location", - "visible": true, - "viewRule": "Public", - "modifyRule": "Self" - }, - { - "name": "Affiliation", - "visible": true, - "viewRule": "Public", - "modifyRule": "Self" - }, - { - "name": "Title", - "visible": true, - "viewRule": "Public", - "modifyRule": "Self" - }, - { - "name": "Homepage", - "visible": true, - "viewRule": "Public", - "modifyRule": "Self" - }, - { - "name": "Bio", - "visible": true, - "viewRule": "Public", - "modifyRule": "Self" - }, - { - "name": "Tag", - "visible": true, - "viewRule": "Public", - "modifyRule": "Admin" - }, - { - "name": "Signup application", - "visible": true, - "viewRule": "Public", - "modifyRule": "Admin" - }, - { - "name": "Roles", - "visible": true, - "viewRule": "Public", - "modifyRule": "Immutable" - }, - { - "name": "Permissions", - "visible": true, - "viewRule": "Public", - "modifyRule": "Immutable" - }, - { - "name": "Groups", - "visible": true, - "viewRule": "Public", - "modifyRule": "Admin" - }, - { - "name": "3rd-party logins", - "visible": true, - "viewRule": "Self", - "modifyRule": "Self" - }, - { - "name": "Properties", - "visible": false, - "viewRule": "Admin", - "modifyRule": "Admin" - }, - { - "name": "Is admin", - "visible": true, - "viewRule": "Admin", - "modifyRule": "Admin" - }, - { - "name": "Is forbidden", - "visible": true, - "viewRule": "Admin", - "modifyRule": "Admin" - }, - { - "name": "Is deleted", - "visible": true, - "viewRule": "Admin", - "modifyRule": "Admin" - }, - { - "name": "Multi-factor authentication", - "visible": true, - "viewRule": "Self", - "modifyRule": "Self" - }, - { - "name": "WebAuthn credentials", - "visible": true, - "viewRule": "Self", - "modifyRule": "Self" - }, - { - "name": "Managed accounts", - "visible": true, - "viewRule": "Self", - "modifyRule": "Self" - } - ] - }, - "certPublicKey": "", - "tags": [], - "samlAttributes": [], - "clientId": "389313df51ffd2093b2f", - "clientSecret": "bd22db46e4ab52ab0d0ac9cbd771a21775039409", - "redirectUris": [ - "http://localhost:8080/callback", - "http://goplus-community-dev.community.svc.jfcs-qa1.local:8080/", - "http://goplus-community-asklv.community.svc.jfcs-qa1.local:8080/", - "http://10.212.223.75:8080//callback", - "http://10.212.196.141:8080//callback" - ], - "tokenFormat": "JWT", - "tokenFields": [], - "expireInHours": 168, - "refreshExpireInHours": 168, - "signupUrl": "", - "signinUrl": "", - "forgetUrl": "", - "affiliationUrl": "", - "termsOfUse": "", - "signupHtml": "", - "signinHtml": "", - "themeData": { - "themeType": "default", - "colorPrimary": "#1677FF", - "borderRadius": 3, - "isCompact": false, - "isEnabled": true - }, - "formCss": "", - "formCssMobile": "", - "formOffset": 2, - "formSideHtml": "", - "formBackgroundUrl": "", - "failedSigninLimit": 5, - "failedSigninFrozenTime": 15 - } - if (provider === null) { - return ""; + + if (provider === null) { + return ""; + } + let endpoint = authInfo[provider.type].endpoint; + let redirectUri = `https://casdoor-community.qiniu.io/callback`; + const scope = authInfo[provider.type].scope; + + // rm (provider.type === "Twitter") + const isShortState = (provider.type === "WeChat" && navigator.userAgent.includes("MicroMessenger")); + const state = getStateFromQueryParams(application.name, provider.name, method, isShortState); + const codeChallenge = "P3S-a7dr8bgM4bF6vOyiKkKETDl16rcAzao9F8UIL1Y"; // SHA256(Base64-URL-encode("casdoor-verifier")) + + if (provider.type === "AzureAD") { + if (provider.domain !== "") { + endpoint = endpoint.replace("common", provider.domain); } - let endpoint = authInfo[provider.type].endpoint; - let redirectUri = `https://casdoor-community.qiniu.io/callback`; - const scope = authInfo[provider.type].scope; - - const isShortState = (provider.type === "WeChat" && navigator.userAgent.includes("MicroMessenger")) || (provider.type === "Twitter"); - const state = getStateFromQueryParams(application.name, provider.name, method, isShortState); - const codeChallenge = "P3S-a7dr8bgM4bF6vOyiKkKETDl16rcAzao9F8UIL1Y"; // SHA256(Base64-URL-encode("casdoor-verifier")) - - if (provider.type === "AzureAD") { - if (provider.domain !== "") { - endpoint = endpoint.replace("common", provider.domain); - } - } else if (provider.type === "Apple") { - redirectUri = `https://casdoor-community.qiniu.io/api/callback`; + } else if (provider.type === "Apple") { + redirectUri = `https://casdoor-community.qiniu.io/api/callback`; + } + + if (provider.type === "Google" || provider.type === "GitHub" || provider.type === "QQ" || provider.type === "Facebook" + || provider.type === "Weibo" || provider.type === "Gitee" || provider.type === "LinkedIn" || provider.type === "GitLab" || provider.type === "AzureAD" + || provider.type === "Slack" || provider.type === "Line" || provider.type === "Amazon" || provider.type === "Auth0" || provider.type === "BattleNet" + || provider.type === "Bitbucket" || provider.type === "Box" || provider.type === "CloudFoundry" || provider.type === "Dailymotion" + || provider.type === "DigitalOcean" || provider.type === "Discord" || provider.type === "Dropbox" || provider.type === "EveOnline" || provider.type === "Gitea" + || provider.type === "Heroku" || provider.type === "InfluxCloud" || provider.type === "Instagram" || provider.type === "Intercom" || provider.type === "Kakao" + || provider.type === "MailRu" || provider.type === "Meetup" || provider.type === "MicrosoftOnline" || provider.type === "Naver" || provider.type === "Nextcloud" + || provider.type === "OneDrive" || provider.type === "Oura" || provider.type === "Patreon" || provider.type === "PayPal" || provider.type === "SalesForce" + || provider.type === "SoundCloud" || provider.type === "Spotify" || provider.type === "Strava" || provider.type === "Stripe" || provider.type === "Tumblr" + || provider.type === "Twitch" || provider.type === "Typetalk" || provider.type === "Uber" || provider.type === "VK" || provider.type === "Wepay" + || provider.type === "Xero" || provider.type === "Yahoo" || provider.type === "Yammer" || provider.type === "Yandex" || provider.type === "Zoom") { + return `${endpoint}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&scope=${scope}&response_type=code&state=${state}`; + } else if (provider.type === "AzureADB2C") { + return `https://${provider.domain}.b2clogin.com/${provider.domain}.onmicrosoft.com/${provider.appId}/oauth2/v2.0/authorize?client_id=${provider.clientId}&nonce=defaultNonce&redirect_uri=${encodeURIComponent(redirectUri)}&scope=${scope}&response_type=code&state=${state}&prompt=login`; + } else if (provider.type === "DingTalk") { + return `${endpoint}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&scope=${scope}&response_type=code&prompt=consent&state=${state}`; + } else if (provider.type === "WeChat") { + if (provider.clientId !== "") { + return `${endpoint}?appid=${provider.clientId}&redirect_uri=${redirectUri}&scope=${scope}&response_type=code&state=${state}#wechat_redirect`; } - - if (provider.type === "Google" || provider.type === "GitHub" || provider.type === "QQ" || provider.type === "Facebook" - || provider.type === "Weibo" || provider.type === "Gitee" || provider.type === "LinkedIn" || provider.type === "GitLab" || provider.type === "AzureAD" - || provider.type === "Slack" || provider.type === "Line" || provider.type === "Amazon" || provider.type === "Auth0" || provider.type === "BattleNet" - || provider.type === "Bitbucket" || provider.type === "Box" || provider.type === "CloudFoundry" || provider.type === "Dailymotion" - || provider.type === "DigitalOcean" || provider.type === "Discord" || provider.type === "Dropbox" || provider.type === "EveOnline" || provider.type === "Gitea" - || provider.type === "Heroku" || provider.type === "InfluxCloud" || provider.type === "Instagram" || provider.type === "Intercom" || provider.type === "Kakao" - || provider.type === "MailRu" || provider.type === "Meetup" || provider.type === "MicrosoftOnline" || provider.type === "Naver" || provider.type === "Nextcloud" - || provider.type === "OneDrive" || provider.type === "Oura" || provider.type === "Patreon" || provider.type === "PayPal" || provider.type === "SalesForce" - || provider.type === "SoundCloud" || provider.type === "Spotify" || provider.type === "Strava" || provider.type === "Stripe" || provider.type === "Tumblr" - || provider.type === "Twitch" || provider.type === "Typetalk" || provider.type === "Uber" || provider.type === "VK" || provider.type === "Wepay" - || provider.type === "Xero" || provider.type === "Yahoo" || provider.type === "Yammer" || provider.type === "Yandex" || provider.type === "Zoom") { - return `${endpoint}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&scope=${scope}&response_type=code&state=${state}`; - } else if (provider.type === "AzureADB2C") { - return `https://${provider.domain}.b2clogin.com/${provider.domain}.onmicrosoft.com/${provider.appId}/oauth2/v2.0/authorize?client_id=${provider.clientId}&nonce=defaultNonce&redirect_uri=${encodeURIComponent(redirectUri)}&scope=${scope}&response_type=code&state=${state}&prompt=login`; - } else if (provider.type === "DingTalk") { - return `${endpoint}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&scope=${scope}&response_type=code&prompt=consent&state=${state}`; - } else if (provider.type === "WeChat") { - if (provider.clientId !== "") { - return `${endpoint}?appid=${provider.clientId}&redirect_uri=${redirectUri}&scope=${scope}&response_type=code&state=${state}#wechat_redirect`; + return `/callback?appid=${provider.clientId2}&redirect_uri=${redirectUri}&scope=${scope}&response_type=code&state=${state}&code=${res?.data2 || ""}`; + } else if (provider.type === "WeCom") { + if (provider.subType === "Internal") { + if (provider.method === "Silent") { + endpoint = authInfo[provider.type].silentEndpoint; + return `${endpoint}?appid=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}&scope=${scope}&response_type=code#wechat_redirect`; + } else if (provider.method === "Normal") { + endpoint = authInfo[provider.type].internalEndpoint; + return `${endpoint}?appid=${provider.clientId}&agentid=${provider.appId}&redirect_uri=${redirectUri}&state=${state}&usertype=member`; + } else { + return `https://error:not-supported-provider-method:${provider.method}`; } - return `/callback?appid=${provider.clientId2}&redirect_uri=${redirectUri}&scope=${scope}&response_type=code&state=${state}&code=${res?.data2 || ""}`; - } else if (provider.type === "WeCom") { - if (provider.subType === "Internal") { - if (provider.method === "Silent") { - endpoint = authInfo[provider.type].silentEndpoint; - return `${endpoint}?appid=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}&scope=${scope}&response_type=code#wechat_redirect`; - } else if (provider.method === "Normal") { - endpoint = authInfo[provider.type].internalEndpoint; - return `${endpoint}?appid=${provider.clientId}&agentid=${provider.appId}&redirect_uri=${redirectUri}&state=${state}&usertype=member`; - } else { - return `https://error:not-supported-provider-method:${provider.method}`; - } - } else if (provider.subType === "Third-party") { - if (provider.method === "Silent") { - endpoint = authInfo[provider.type].silentEndpoint; - return `${endpoint}?appid=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}&scope=${scope}&response_type=code#wechat_redirect`; - } else if (provider.method === "Normal") { - return `${endpoint}?appid=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}&usertype=member`; - } else { - return `https://error:not-supported-provider-method:${provider.method}`; - } + } else if (provider.subType === "Third-party") { + if (provider.method === "Silent") { + endpoint = authInfo[provider.type].silentEndpoint; + return `${endpoint}?appid=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}&scope=${scope}&response_type=code#wechat_redirect`; + } else if (provider.method === "Normal") { + return `${endpoint}?appid=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}&usertype=member`; } else { - return `https://error:not-supported-provider-sub-type:${provider.subType}`; + return `https://error:not-supported-provider-method:${provider.method}`; } - } else if (provider.type === "Lark") { - return `${endpoint}?app_id=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}`; - } else if (provider.type === "ADFS") { - return `${provider.domain}/adfs/oauth2/authorize?client_id=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}&response_type=code&nonce=casdoor&scope=openid`; - } else if (provider.type === "Baidu") { - return `${endpoint}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}&response_type=code&scope=${scope}&display=popup`; - } else if (provider.type === "Alipay") { - return `${endpoint}?app_id=${provider.clientId}&scope=auth_user&redirect_uri=${redirectUri}&state=${state}&response_type=code&scope=${scope}&display=popup`; - } else if (provider.type === "Casdoor") { - return `${provider.domain}/login/oauth/authorize?client_id=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}&response_type=code&scope=${scope}`; - } else if (provider.type === "Infoflow") { - return `${endpoint}?appid=${provider.clientId}&redirect_uri=${redirectUri}?state=${state}`; - } else if (provider.type === "Apple") { - return `${endpoint}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}&response_type=code%20id_token&scope=${scope}&response_mode=form_post`; - } else if (provider.type === "Steam") { - return `${endpoint}?openid.claimed_id=http://specs.openid.net/auth/2.0/identifier_select&openid.identity=http://specs.openid.net/auth/2.0/identifier_select&openid.mode=checkid_setup&openid.ns=http://specs.openid.net/auth/2.0&openid.realm=https://casdoor-community.qiniu.io&openid.return_to=${redirectUri}?state=${state}`; - } else if (provider.type === "Okta") { - return `${provider.domain}/v1/authorize?client_id=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}&response_type=code&scope=${scope}`; - } else if (provider.type === "Douyin" || provider.type === "TikTok") { - return `${endpoint}?client_key=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}&response_type=code&scope=${scope}`; - } else if (provider.type === "Custom") { - return `${provider.customAuthUrl}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&scope=${provider.scopes}&response_type=code&state=${state}`; - } else if (provider.type === "Bilibili") { - return `${endpoint}#/?client_id=${provider.clientId}&return_url=${redirectUri}&state=${state}&response_type=code`; - } else if (provider.type === "Deezer") { - return `${endpoint}?app_id=${provider.clientId}&redirect_uri=${redirectUri}&perms=${scope}`; - } else if (provider.type === "Lastfm") { - return `${endpoint}?api_key=${provider.clientId}&cb=${redirectUri}`; - } else if (provider.type === "Shopify") { - return `${endpoint}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&scope=${scope}&state=${state}&grant_options[]=per-user`; - } else if (provider.type === "Twitter" || provider.type === "Fitbit") { - return `${endpoint}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}&response_type=code&scope=${scope}&code_challenge=${codeChallenge}&code_challenge_method=S256`; - } else if (provider.type === "MetaMask") { - return `${redirectUri}?state=${state}`; - } else if (provider.type === "Web3Onboard") { - return `${redirectUri}?state=${state}`; + } else { + return `https://error:not-supported-provider-sub-type:${provider.subType}`; } + } else if (provider.type === "Lark") { + return `${endpoint}?app_id=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}`; + } else if (provider.type === "ADFS") { + return `${provider.domain}/adfs/oauth2/authorize?client_id=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}&response_type=code&nonce=casdoor&scope=openid`; + } else if (provider.type === "Baidu") { + return `${endpoint}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}&response_type=code&scope=${scope}&display=popup`; + } else if (provider.type === "Alipay") { + return `${endpoint}?app_id=${provider.clientId}&scope=auth_user&redirect_uri=${redirectUri}&state=${state}&response_type=code&scope=${scope}&display=popup`; + } else if (provider.type === "Casdoor") { + return `${provider.domain}/login/oauth/authorize?client_id=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}&response_type=code&scope=${scope}`; + } else if (provider.type === "Infoflow") { + return `${endpoint}?appid=${provider.clientId}&redirect_uri=${redirectUri}?state=${state}`; + } else if (provider.type === "Apple") { + return `${endpoint}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}&response_type=code%20id_token&scope=${scope}&response_mode=form_post`; + } else if (provider.type === "Steam") { + return `${endpoint}?openid.claimed_id=http://specs.openid.net/auth/2.0/identifier_select&openid.identity=http://specs.openid.net/auth/2.0/identifier_select&openid.mode=checkid_setup&openid.ns=http://specs.openid.net/auth/2.0&openid.realm=https://casdoor-community.qiniu.io&openid.return_to=${redirectUri}?state=${state}`; + } else if (provider.type === "Okta") { + return `${provider.domain}/v1/authorize?client_id=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}&response_type=code&scope=${scope}`; + } else if (provider.type === "Douyin" || provider.type === "TikTok") { + return `${endpoint}?client_key=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}&response_type=code&scope=${scope}`; + } else if (provider.type === "Custom") { + return `${provider.customAuthUrl}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&scope=${provider.scopes}&response_type=code&state=${state}`; + } else if (provider.type === "Bilibili") { + return `${endpoint}#/?client_id=${provider.clientId}&return_url=${redirectUri}&state=${state}&response_type=code`; + } else if (provider.type === "Deezer") { + return `${endpoint}?app_id=${provider.clientId}&redirect_uri=${redirectUri}&perms=${scope}`; + } else if (provider.type === "Lastfm") { + return `${endpoint}?api_key=${provider.clientId}&cb=${redirectUri}`; + } else if (provider.type === "Shopify") { + return `${endpoint}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&scope=${scope}&state=${state}&grant_options[]=per-user`; + } else if (provider.type === "Twitter" || provider.type === "Fitbit") { + return `${endpoint}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}&response_type=code&scope=${scope}&code_challenge=${codeChallenge}&code_challenge_method=S256`; + } else if (provider.type === "MetaMask") { + return `${redirectUri}?state=${state}`; + } else if (provider.type === "Web3Onboard") { + return `${redirectUri}?state=${state}`; } +} - const app = Vue.createApp({ - data() { - return { - accountList: [ +const app = Vue.createApp({ + data() { + return { + accountList: [ + { + img: "static/img/social_github.png", + platform: "Github", + desc: "website: https://github.com", + bind: accountBinds.github, + provider: authInfo.GitHub, + url: getAuthUrl(providers[0], "link") + }, { - img: "static/img/social_github.png", - platform: "Github", - desc: "website: https://github.com", - bind: false, - provider: authInfo.GitHub, - url: getAuthUrl(providers[0], "link") - }, - { - img: "static/img/social_twitter.png", - platform: "Twitter / X", - desc: "website: https://twitter.com", - bind: false, - provider: authInfo.Twitter, - url: getAuthUrl(providers[1], "link") - }, - { - img: "static/img/social_facebook.png", - platform: "Facebook", - desc: "website: https://facebook.com", - bind: false, - provider: authInfo.Facebook, - url: getAuthUrl(providers[2], "link") - }, - { - img: "static/img/social_wechat.png", - platform: "Wechat", - desc: "website: https://weixin.qq.com", - bind: false, - provider: authInfo.WeChat, - url: getAuthUrl(providers[3], "link") - } - ] - }; - }, - methods: { - - }, - }); - app.use(naive); - app.config.compilerOptions.delimiters = ["${", "}"]; - app.mount("#app"); \ No newline at end of file + img: "static/img/social_twitter.png", + platform: "Twitter", + desc: "Twitter / X, website: https://twitter.com", + bind: accountBinds.twitter, + provider: authInfo.Twitter, + url: getAuthUrl(providers[1], "link") + }, + { + img: "static/img/social_facebook.png", + platform: "Facebook", + desc: "website: https://facebook.com", + bind: accountBinds.facebook, + provider: authInfo.Facebook, + url: getAuthUrl(providers[2], "link") + }, + { + img: "static/img/social_wechat.png", + platform: "Wechat", + desc: "website: https://weixin.qq.com", + bind: accountBinds.wechat, + provider: authInfo.WeChat, + url: getAuthUrl(providers[3], "link") + } + ] + }; + }, + methods: { + + }, +}); +app.use(naive); +app.config.compilerOptions.delimiters = ["${", "}"]; +app.mount("#app"); + diff --git a/cmd/gopcomm/yap/user_edit_yap.html b/cmd/gopcomm/yap/user_edit_yap.html index cf82fd07..b0fda9cc 100644 --- a/cmd/gopcomm/yap/user_edit_yap.html +++ b/cmd/gopcomm/yap/user_edit_yap.html @@ -3,7 +3,7 @@ - user info editsefsf + user info edit {{ template "header" .}} @@ -102,6 +102,7 @@

> @@ -127,6 +128,15 @@

Bind + + unLink @@ -134,6 +144,10 @@

+ diff --git a/internal/core/casdoor.go b/internal/core/casdoor.go new file mode 100644 index 00000000..347b3def --- /dev/null +++ b/internal/core/casdoor.go @@ -0,0 +1,79 @@ +package core + +import ( + "bytes" + "encoding/json" + "io" + "log" + "net/http" + + "github.com/casdoor/casdoor-go-sdk/casdoorsdk" +) + +// get community application information +func (a *Community) GetApplicationInfo() (*casdoorsdk.Application, error) { + a2, err := casdoorsdk.GetApplication("application_x8aevk") + if err != nil { + log.Println(err) + } + return a2, err +} + +func (p *Community) GetAccountBinds(token string) map[string]bool { + claim, err := casdoorsdk.ParseJwtToken(token) + if err != nil { + p.xLog.Error(err) + return map[string]bool{} + } + u, err := casdoorsdk.GetUser(claim.Name) + if err != nil { + return map[string]bool{} + } + + return map[string]bool{ + "twitter": len(u.Twitter) > 0, + "github": len(u.GitHub) > 0, + "facebook": len(u.Facebook) > 0, + "wechat": len(u.WeChat) > 0, + } +} + +func (p *Community) UnLink(token, provider string) bool { + claim, err := casdoorsdk.ParseJwtToken(token) + if err != nil { + p.xLog.Error(err) + return false + } + u, err := casdoorsdk.GetUser(claim.Name) + if err != nil { + log.Println(err) + return false + } + postData, _ := json.Marshal(map[string]interface{}{ + "providerType": provider, + "user": u, + }) + + var response casdoorsdk.Response + targetUrl := casdoorsdk.GetUrl("unlink", map[string]string{ + "access_token": token, + }) + req, _ := http.NewRequest("POST", targetUrl, bytes.NewReader(postData)) + + req.Header.Add("Content-Type", "application/json") + resultBody, _ := http.DefaultClient.Do(req) + body, err := io.ReadAll(resultBody.Body) + if err != nil { + return false + } + err = json.Unmarshal(body, &response) + if err != nil { + return false + } + + if response.Status != "ok" { + log.Println(response.Msg) + return false + } + return true +} diff --git a/internal/core/casdoor_test.go b/internal/core/casdoor_test.go new file mode 100644 index 00000000..e29f8e41 --- /dev/null +++ b/internal/core/casdoor_test.go @@ -0,0 +1,42 @@ +package core + +import ( + "context" + "encoding/json" + "testing" +) + +func TestGetApplicationInfo(t *testing.T) { + conf := &Config{} + todo := context.TODO() + community, err := New(todo, conf) + + if err != nil { + t.Skip(err) + } + a, _ := community.GetApplicationInfo() + b, err := json.Marshal(*a) + t.Log(string(b), err) +} + +const token = "eyJhbGciOiJSUzI1NiIsImtpZCI6ImNlcnQtYnVpbHQtaW4iLCJ0eXAiOiJKV1QifQ.eyJvd25lciI6IkdvUGx1cyIsIm5hbWUiOiJDcmFmdExpdXMiLCJjcmVhdGVkVGltZSI6IjIwMjQtMDItMTlUMDM6MjI6MDRaIiwidXBkYXRlZFRpbWUiOiIyMDI0LTAyLTE5VDEwOjA1OjUxWiIsImRlbGV0ZWRUaW1lIjoiIiwiaWQiOiIxMjI0NDA1OTIwMjYxNjIzODA5IiwidHlwZSI6Im5vcm1hbC11c2VyIiwicGFzc3dvcmQiOiIiLCJwYXNzd29yZFNhbHQiOiIiLCJwYXNzd29yZFR5cGUiOiJwbGFpbiIsImRpc3BsYXlOYW1lIjoiZHJnZ2R3ZWFmYSIsImZpcnN0TmFtZSI6IiIsImxhc3ROYW1lIjoiIiwiYXZhdGFyIjoiaHR0cHM6Ly9hdmF0YXJzLmdpdGh1YnVzZXJjb250ZW50LmNvbS91LzQ3MDYyODMyP3Y9NCIsImF2YXRhclR5cGUiOiIiLCJwZXJtYW5lbnRBdmF0YXIiOiIiLCJlbWFpbCI6IiIsImVtYWlsVmVyaWZpZWQiOmZhbHNlLCJwaG9uZSI6IiIsImNvdW50cnlDb2RlIjoiIiwicmVnaW9uIjoiIiwibG9jYXRpb24iOiIiLCJhZGRyZXNzIjpbXSwiYWZmaWxpYXRpb24iOiIiLCJ0aXRsZSI6IiIsImlkQ2FyZFR5cGUiOiIiLCJpZENhcmQiOiIiLCJob21lcGFnZSI6IiIsImJpbyI6IiIsImxhbmd1YWdlIjoiIiwiZ2VuZGVyIjoiIiwiYmlydGhkYXkiOiIiLCJlZHVjYXRpb24iOiIiLCJzY29yZSI6MCwia2FybWEiOjAsInJhbmtpbmciOjcsImlzRGVmYXVsdEF2YXRhciI6ZmFsc2UsImlzT25saW5lIjpmYWxzZSwiaXNBZG1pbiI6ZmFsc2UsImlzRm9yYmlkZGVuIjpmYWxzZSwiaXNEZWxldGVkIjpmYWxzZSwic2lnbnVwQXBwbGljYXRpb24iOiJhcHBsaWNhdGlvbl94OGFldmsiLCJoYXNoIjoiIiwicHJlSGFzaCI6IiIsImFjY2Vzc0tleSI6IiIsImFjY2Vzc1NlY3JldCI6IiIsImdpdGh1YiI6IjQ3MDYyODMyIiwiZ29vZ2xlIjoiIiwicXEiOiIiLCJ3ZWNoYXQiOiIiLCJmYWNlYm9vayI6IiIsImRpbmd0YWxrIjoiIiwid2VpYm8iOiIiLCJnaXRlZSI6IiIsImxpbmtlZGluIjoiIiwid2Vjb20iOiIiLCJsYXJrIjoiIiwiZ2l0bGFiIjoiIiwiY3JlYXRlZElwIjoiIiwibGFzdFNpZ25pblRpbWUiOiIiLCJsYXN0U2lnbmluSXAiOiIiLCJwcmVmZXJyZWRNZmFUeXBlIjoiIiwicmVjb3ZlcnlDb2RlcyI6bnVsbCwidG90cFNlY3JldCI6IiIsIm1mYVBob25lRW5hYmxlZCI6ZmFsc2UsIm1mYUVtYWlsRW5hYmxlZCI6ZmFsc2UsImxkYXAiOiIiLCJwcm9wZXJ0aWVzIjp7Im5vIjoiOCIsIm9hdXRoX0dpdEh1Yl9hdmF0YXJVcmwiOiJodHRwczovL2F2YXRhcnMuZ2l0aHVidXNlcmNvbnRlbnQuY29tL3UvNDcwNjI4MzI_dj00Iiwib2F1dGhfR2l0SHViX2Rpc3BsYXlOYW1lIjoiTGl1c0NyYWZ0Iiwib2F1dGhfR2l0SHViX2lkIjoiNDcwNjI4MzIiLCJvYXV0aF9HaXRIdWJfdXNlcm5hbWUiOiJMaXVzQ3JhZnQiLCJvYXV0aF9Ud2l0dGVyX2Rpc3BsYXlOYW1lIjoiZHJnZ2R3ZWFmYSIsIm9hdXRoX1R3aXR0ZXJfaWQiOiIxMjI0NDA1OTIwMjYxNjIzODA5Iiwib2F1dGhfVHdpdHRlcl91c2VybmFtZSI6IkNyYWZ0TGl1cyJ9LCJyb2xlcyI6W10sInBlcm1pc3Npb25zIjpbXSwiZ3JvdXBzIjpbXSwibGFzdFNpZ25pbldyb25nVGltZSI6IiIsInNpZ25pbldyb25nVGltZXMiOjAsInRva2VuVHlwZSI6ImFjY2Vzcy10b2tlbiIsInRhZyI6IiIsInNjb3BlIjoicmVhZCIsImlzcyI6Imh0dHBzOi8vY2FzZG9vci1jb21tdW5pdHkucWluaXUuaW8iLCJzdWIiOiIxMjI0NDA1OTIwMjYxNjIzODA5IiwiYXVkIjpbIjM4OTMxM2RmNTFmZmQyMDkzYjJmIl0sImV4cCI6MTcwODk0MTk1MSwibmJmIjoxNzA4MzM3MTUxLCJpYXQiOjE3MDgzMzcxNTEsImp0aSI6ImFkbWluL2MxYTE1ZDJkLWE1MGItNDc1MS1hN2JlLTRlYTFhZGU2MjBjOCJ9.SuS-I4QoBhgPXv7sUZoWIwSZvavupZgos_6cZNh-MkJD6DUd_87enT16NlSL-nqZ9hTN0cZUJOpjTmhmUEq-L8CZAp9dN_uJwN-l5VUIwIJAhI4l0jhNXmrO5Y7yaoI0qTbg21MmeLpyuN9KPIFBjB7iwlnXI43iiYcUn01rmlbi-8x5MVlOdpdGH_KfgGbHo_S7GanLk8bHCagMdEfQUFRwjO-n2czVN5LqbSCBGvOxKss1zerrlzMuvZwfust6PYhpmsXyTMu_brWn5NOyj5YUlbAP8YDaWTTqjwIglEloWB95elLwFACxe7eS_sRDWlfa9yS6d-1coIBg5WdGV_3LfeQKW7HwB9xvjgqsoewH62ulgYRJp8HcI8L26V_aSkn94eCxRK_iF-9egSfDmCuS07rfScLxokztkMpnuGEThsDF9Cwm5ttP-6DvlP5uPjKO_zWVMig-2jmah_c85zMi7ELiMTpVl2EfY3PxrBrhh__QpWt22Y6g8Dc3FLSbUOGz_iYISpTg6Cq1u9a_F0oHH_q0xnuAmP_DrKpYIPm829wFR1_6mmajCzvr1blDutIkM8ebYroZPwEZEqlnT_2eSaPIrOVqvLd_56Du9dy8OkRL01dbjUsAbmshDbGrGm4nMBpJsH6E16XM9_R6BcWyB703AotIFD_ZqKUjPS0" + +func TestGetAccountBinds(t *testing.T) { + conf := &Config{} + todo := context.TODO() + community, err := New(todo, conf) + if err != nil { + t.Skip(err) + } + t.Log(community.GetAccountBinds(token)) +} + +func TestAccountUnLink(t *testing.T) { + conf := &Config{} + todo := context.TODO() + community, err := New(todo, conf) + if err != nil { + t.Skip(err) + } + t.Log(community.UnLink(token, "Twitter")) +} diff --git a/internal/core/user.go b/internal/core/user.go index ad55f31c..262f950e 100644 --- a/internal/core/user.go +++ b/internal/core/user.go @@ -1,10 +1,11 @@ package core import ( - "github.com/goplus/yap" "net/http" "os" + "github.com/goplus/yap" + "github.com/casdoor/casdoor-go-sdk/casdoorsdk" )