-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Casdoor login include github login #49
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2bf279a
Add files via upload
wu-jj 4582346
Update community_yap.gox
wu-jj 5e78df3
casdoor config
wu-jj 96366d0
Update gop_autogen.go
wu-jj 282a033
Update community_yap.gox
wu-jj 7639378
Update community.gop
wu-jj c9ddd49
Update callback_yap.html
wu-jj 8fdd02e
Delete login/service/gop_autogen.go
wu-jj c54c63f
delete note
wu-jj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,43 @@ | ||
import ( | ||
"github.com/casdoor/casdoor-go-sdk/casdoorsdk" | ||
) | ||
|
||
type CasdoorConfig struct { | ||
endPoint string | ||
clientId string | ||
clientSecret string | ||
certificate string | ||
organizationName string | ||
applicationName string | ||
} | ||
|
||
func init() { | ||
conf := new(CasdoorConfig) | ||
|
||
endPoint := conf.endPoint | ||
clientID := conf.clientId | ||
clientSecret := conf.clientSecret | ||
certificate := conf.certificate | ||
organizationName := conf.organizationName | ||
applicationName := conf.applicationName | ||
//TODO Post insertion of environmental variables | ||
if endPoint == "" { | ||
endPoint = os.Getenv("GOP_CASDOOR_ENDPOINT") | ||
} | ||
if clientID == "" { | ||
clientID = os.Getenv("GOP_CASDOOR_CLIENTID") | ||
} | ||
if clientSecret == "" { | ||
clientSecret = os.Getenv("GOP_CASDOOR_CLIENTSECRET") | ||
} | ||
if certificate == "" { | ||
certificate = os.Getenv("GOP_CASDOOR_CERTIFICATE") | ||
} | ||
if organizationName == "" { | ||
organizationName = os.Getenv("GOP_CASDOOR_ORGANIZATIONNAME") | ||
} | ||
if applicationName == "" { | ||
applicationName = os.Getenv("GOP_CASDOOR_APPLICATONNAME") | ||
} | ||
casdoorsdk.InitConfig(endPoint, clientID, clientSecret, certificate, organizationName, applicationName) | ||
} |
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,74 @@ | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"net/http" | ||
"github.com/casdoor/casdoor-go-sdk/casdoorsdk" | ||
"os" | ||
) | ||
|
||
|
||
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) | ||
http.Redirect(ctx.ResponseWriter,ctx.Request,loginURL, http.StatusFound) | ||
} | ||
|
||
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) | ||
token, err := casdoorsdk.GetOAuthToken(code, state) | ||
if err != nil { | ||
fmt.Println("err",err) | ||
} | ||
claim, err := casdoorsdk.ParseJwtToken(token.AccessToken) | ||
if err != nil { | ||
log.Fatal("err",err) | ||
} | ||
username := claim.User.Name | ||
ctx.yap "callback", { | ||
"username": username, | ||
"usertoken":token.AccessToken, | ||
} | ||
|
||
|
||
|
||
} | ||
|
||
get "/test", ctx => { | ||
cookie, _ := ctx.Request.Cookie("token") | ||
claim, err := casdoorsdk.ParseJwtToken(cookie.Value) | ||
if err != nil { | ||
log.Fatal("err",err)//跳转到登录界面 | ||
}else { | ||
fmt.Println("username:",claim.User.Name) | ||
fmt.Println("userId:",claim.User.Id) | ||
fmt.Println("password:",claim.User.Password) | ||
} | ||
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,16 @@ | ||
<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}} | ||
document.cookie = "token="+token | ||
</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> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete comment