-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
263 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"net/http" | ||
"github.com/casdoor/casdoor-go-sdk/casdoorsdk" | ||
|
||
) | ||
|
||
// store := sessions.NewCookieStore([]byte("QiNiu")) | ||
|
||
// 创建一个全局的存储会话的map | ||
// var sessionMap = make(map[string]*http.Cookie) | ||
|
||
endPoint := "https://casdoor-community.qiniu.io" | ||
clientID := "49a8ac9729e314a05bf0" | ||
clientSecret := "9ff5d5be617618c92180c668ff28562271f310b4" | ||
certificate := "-----BEGIN CERTIFICATE-----\nMIIE3TCCAsWgAwIBAgIDAeJAMA0GCSqGSIb3DQEBCwUAMCgxDjAMBgNVBAoTBWFk\nbWluMRYwFAYDVQQDEw1jZXJ0LWJ1aWx0LWluMB4XDTI0MDExMDA5MjUxNVoXDTQ0\nMDExMDA5MjUxNVowKDEOMAwGA1UEChMFYWRtaW4xFjAUBgNVBAMTDWNlcnQtYnVp\nbHQtaW4wggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQDZ6k0hJ5aCOgHI\nkLY+doPSYI/WB0F36saOKtGolxA1j6p99sJZTVRDocsseQj6EGIXKdRi58H5ncfG\nIjE7ePoKVI+U4e67VtE1Y5fmI6Dg740tSh7q1+IJkCHZ06dz24irzgVDWMiEl5eQ\n+ekq5ebN0zCIK/MFE0QEraWp3jX3MXiiBshnZgbI8TMyQCD0CNR/OiB+9VEzUlQO\nBQAGefzOZkj7NxV9USnVu5TsQBvEzL43hlrQ5c5NgbRg8VGKluByNCniSftRP08H\nUebc2nFc0cbV9vkyCm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3gtJMx1GVjMhNck\npOXpMCdMP22XpVFd/uKXdCd9tGGJUd5C+ZvcsThY9susU/LilAL9WQbhH1amJDsG\nbQ==\n-----END CERTIFICATE-----" | ||
organizationName := "built-in" | ||
applicationName := "application_ot2837" | ||
casdoorsdk.InitConfig(endPoint, clientID, clientSecret, certificate, organizationName, applicationName) | ||
|
||
|
||
get "/p/:id", ctx => { | ||
ctx.yap "article", { | ||
"id": ctx.param("id"), | ||
} | ||
} | ||
get "/", ctx => { | ||
ctx.yap "home", {} | ||
} | ||
|
||
|
||
|
||
|
||
get "/login",ctx => { | ||
casdoorURL := "https://casdoor-community.qiniu.io" | ||
clientID := "49a8ac9729e314a05bf0" | ||
redirectURI := "http://localhost:8080/callback" | ||
ResponseType := "code" | ||
Scope := "read" | ||
State := "casdoor" | ||
loginURL := fmt.Sprintf("%s/login/oauth/authorize?client_id=%s&response_type=%s&redirect_uri=%s&scope=%s&state=%s",casdoorURL,clientID,ResponseType,redirectURI,Scope,State) | ||
//line cmd/gopcomm/community_yap.gox:24:1 | ||
http.Redirect(ctx.ResponseWriter,ctx.Request,loginURL, http.StatusFound) | ||
} | ||
|
||
//获取token | ||
get "/callback", ctx => { | ||
|
||
code :=ctx.URL.Query().Get("code") | ||
state :=ctx.URL.Query().Get("state") | ||
fmt.Println("--code and state--") | ||
fmt.Println("code:",code) | ||
fmt.Println("state:",state) | ||
// fmt.Println("========================================println token======================================") | ||
token, err := casdoorsdk.GetOAuthToken(code, state) | ||
if err != nil { | ||
fmt.Println("err",err) | ||
} | ||
//fmt.Println("==============================================parse token==============================") | ||
claim, err := casdoorsdk.ParseJwtToken(token.AccessToken) | ||
if err != nil { | ||
log.Fatal("err",err) | ||
}else { | ||
// fmt.Println(claim.User.Name) | ||
} | ||
fmt.Println("============================================================") | ||
username := claim.User.Name | ||
ctx.yap "callback", { | ||
"username": username, | ||
"usertoken":token.AccessToken, | ||
} | ||
|
||
|
||
|
||
} | ||
|
||
get "/test", ctx => { | ||
cookie, _ := ctx.Request.Cookie("token") | ||
// fmt.Println("-----------------------------------------------------") | ||
// fmt.Println(cookie.Value) | ||
claim, err := casdoorsdk.ParseJwtToken(cookie.Value) | ||
if err != nil { | ||
log.Fatal("err",err)//跳转到登录界面 | ||
}else { | ||
fmt.Println(claim.User.Name) | ||
} | ||
ctx.yap "test", {} | ||
|
||
} | ||
|
||
|
||
run ":8080" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/goplus/yap" | ||
"log" | ||
"net/http" | ||
"github.com/casdoor/casdoor-go-sdk/casdoorsdk" | ||
Check failure on line 8 in login/service/gop_autogen.go GitHub Actions / build (1.19.x, ubuntu-latest)
|
||
) | ||
|
||
type community struct { | ||
yap.App | ||
} | ||
//line login/login/service/community_yap.gox:15 | ||
func (this *community) MainEntry() { | ||
//line login/login/service/community_yap.gox:15:1 | ||
endPoint := "https://casdoor-community.qiniu.io" | ||
//line login/login/service/community_yap.gox:16:1 | ||
clientID := "49a8ac9729e314a05bf0" | ||
//line login/login/service/community_yap.gox:17:1 | ||
clientSecret := "9ff5d5be617618c92180c668ff28562271f310b4" | ||
//line login/login/service/community_yap.gox:18:1 | ||
certificate := "-----BEGIN CERTIFICATE-----\nMIIE3TCCAsWgAwIBAgIDAeJAMA0GCSqGSIb3DQEBCwUAMCgxDjAMBgNVBAoTBWFk\nbWluMRYwFAYDVQQDEw1jZXJ0LWJ1aWx0LWluMB4XDTI0MDExMDA5MjUxNVoXDTQ0\nMDExMDA5MjUxNVowKDEOMAwGA1UEChMFYWRtaW4xFjAUBgNVBAMTDWNlcnQtYnVp\nbHQtaW4wggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQDZ6k0hJ5aCOgHI\nkLY+doPSYI/WB0F36saOKtGolxA1j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QYeLC1QSc\nfnK6gliAmB86HeYSxUscimTXOtdRNNopuik4x36V1q3ZislEXOUgiGJvx/rGVicC\nTVXs8+5eexakcGteA3FDp95RCVFBedMGzjXPEbnNs2th4DPUQZvOLUtCB1BZwfE8\nEXkJGv/WFKqdQszfKl3hFxocmZppciLV+rTFMnZNNSXcIZIn1n7kEPy/2Teq0ObI\n7FqI+/gZu2Shw82RBcVtrTfRqY51S/a/lB9Ofu2kGnR05XzVX3gtJMx1GVjMhNck\npOXpMCdMP22XpVFd/uKXdCd9tGGJUd5C+ZvcsThY9susU/LilAL9WQbhH1amJDsG\nbQ==\n-----END CERTIFICATE-----" | ||
//line login/login/service/community_yap.gox:19:1 | ||
organizationName := "built-in" | ||
//line login/login/service/community_yap.gox:20:1 | ||
applicationName := "application_ot2837" | ||
//line login/login/service/community_yap.gox:21:1 | ||
casdoorsdk.InitConfig(endPoint, clientID, clientSecret, certificate, organizationName, applicationName) | ||
//line login/login/service/community_yap.gox:24:1 | ||
this.Get("/p/:id", func(ctx *yap.Context) { | ||
//line login/login/service/community_yap.gox:25:1 | ||
ctx.Yap__1("article", map[string]string{"id": ctx.Param("id")}) | ||
}) | ||
//line login/login/service/community_yap.gox:29:1 | ||
this.Get("/", func(ctx *yap.Context) { | ||
//line login/login/service/community_yap.gox:30:1 | ||
ctx.Yap__1("home", map[string]interface { | ||
}{}) | ||
}) | ||
//line login/login/service/community_yap.gox:36:1 | ||
this.Get("/login", func(ctx *yap.Context) { | ||
//line login/login/service/community_yap.gox:37:1 | ||
casdoorURL := "https://casdoor-community.qiniu.io" | ||
//line login/login/service/community_yap.gox:38:1 | ||
clientID := "49a8ac9729e314a05bf0" | ||
//line login/login/service/community_yap.gox:39:1 | ||
redirectURI := "http://localhost:8080/callback" | ||
//line login/login/service/community_yap.gox:40:1 | ||
ResponseType := "code" | ||
//line login/login/service/community_yap.gox:41:1 | ||
Scope := "read" | ||
//line login/login/service/community_yap.gox:42:1 | ||
State := "casdoor" | ||
//line login/login/service/community_yap.gox:43:1 | ||
loginURL := fmt.Sprintf("%s/login/oauth/authorize?client_id=%s&response_type=%s&redirect_uri=%s&scope=%s&state=%s", casdoorURL, clientID, ResponseType, redirectURI, Scope, State) | ||
//line login/login/service/community_yap.gox:45:1 | ||
http.Redirect(ctx.ResponseWriter, ctx.Request, loginURL, http.StatusFound) | ||
}) | ||
//line login/login/service/community_yap.gox:49:1 | ||
this.Get("/callback", func(ctx *yap.Context) { | ||
//line login/login/service/community_yap.gox:51:1 | ||
code := ctx.URL.Query().Get("code") | ||
//line login/login/service/community_yap.gox:52:1 | ||
state := ctx.URL.Query().Get("state") | ||
//line login/login/service/community_yap.gox:53:1 | ||
fmt.Println("--code and state--") | ||
//line login/login/service/community_yap.gox:54:1 | ||
fmt.Println("code:", code) | ||
//line login/login/service/community_yap.gox:55:1 | ||
fmt.Println("state:", state) | ||
//line login/login/service/community_yap.gox:57:1 | ||
token, err := casdoorsdk.GetOAuthToken(code, state) | ||
//line login/login/service/community_yap.gox:58:1 | ||
if err != nil { | ||
//line login/login/service/community_yap.gox:59:1 | ||
fmt.Println("err", err) | ||
} | ||
//line login/login/service/community_yap.gox:62:1 | ||
claim, err := casdoorsdk.ParseJwtToken(token.AccessToken) | ||
//line login/login/service/community_yap.gox:63:1 | ||
if err != nil { | ||
//line login/login/service/community_yap.gox:64:1 | ||
log.Fatal("err", err) | ||
} else { | ||
} | ||
//line login/login/service/community_yap.gox:68:1 | ||
fmt.Println("============================================================") | ||
//line login/login/service/community_yap.gox:69:1 | ||
username := claim.User.Name | ||
//line login/login/service/community_yap.gox:70:1 | ||
ctx.Yap__1("callback", map[string]string{"username": username, "usertoken": token.AccessToken}) | ||
}) | ||
//line login/login/service/community_yap.gox:79:1 | ||
this.Get("/test", func(ctx *yap.Context) { | ||
//line login/login/service/community_yap.gox:80:1 | ||
cookie, _ := ctx.Request.Cookie("token") | ||
//line login/login/service/community_yap.gox:83:1 | ||
claim, err := casdoorsdk.ParseJwtToken(cookie.Value) | ||
//line login/login/service/community_yap.gox:84:1 | ||
if err != nil { | ||
//line login/login/service/community_yap.gox:85:1 | ||
log.Fatal("err", err) | ||
} else { | ||
//line login/login/service/community_yap.gox:87:1 | ||
fmt.Println(claim.User.Name) | ||
} | ||
//line login/login/service/community_yap.gox:89:1 | ||
ctx.Yap__1("test", map[string]interface { | ||
}{}) | ||
}) | ||
//line login/login/service/community_yap.gox:94:1 | ||
this.Run__1(":8080") | ||
} | ||
func main() { | ||
yap.Gopt_App_Main(new(community)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<html> | ||
<head> | ||
<meta charset="utf-8"/> | ||
</head> | ||
<body> | ||
<h1>This is callback page </h1> | ||
<h1> username :{{.username}} </h1> | ||
<h2>Go+ Community test page <a href="/test">go!</a></h2> | ||
</body> | ||
|
||
|
||
<script> | ||
var token = {{.usertoken}} | ||
console.log(token) | ||
|
||
|
||
console.log("===============================================") | ||
document.cookie = "token="+token | ||
|
||
|
||
|
||
console.log(document.cookie) | ||
|
||
</script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<html> | ||
<head> | ||
<meta charset="utf-8"/> | ||
</head> | ||
<body> | ||
Go+ Community <a href="/p/123">written in Go+</a> | ||
<a href="/login">login</a> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<html> | ||
<head> | ||
<meta charset="utf-8"/> | ||
|
||
</head> | ||
<body> | ||
Go+ Community <a href="/p/123">written in Go+</a> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<html> | ||
<head> | ||
<meta charset="utf-8"/> | ||
|
||
</head> | ||
<body> | ||
<h1>test page</h1> | ||
</body> | ||
</html> |