You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

account.go 1.2 kB

3 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package controllers
  2. import (
  3. _ "embed"
  4. "github.com/astaxie/beego"
  5. "github.com/casdoor/casdoor-go-sdk/auth"
  6. )
  7. //go:embed token_jwt_key.pem
  8. var JwtPublicKey string
  9. func init() {
  10. InitAuthConfig()
  11. }
  12. func InitAuthConfig() {
  13. casdoorEndpoint := beego.AppConfig.String("casdoorEndpoint")
  14. clientId := beego.AppConfig.String("clientId")
  15. clientSecret := beego.AppConfig.String("clientSecret")
  16. casdoorOrganization := beego.AppConfig.String("casdoorOrganization")
  17. casdoorApplication := beego.AppConfig.String("casdoorApplication")
  18. auth.InitConfig(casdoorEndpoint, clientId, clientSecret, JwtPublicKey, casdoorOrganization, casdoorApplication)
  19. }
  20. func (c *ApiController) Signin() {
  21. code := c.Input().Get("code")
  22. state := c.Input().Get("state")
  23. token, err := auth.GetOAuthToken(code, state)
  24. if err != nil {
  25. panic(err)
  26. }
  27. claims, err := auth.ParseJwtToken(token.AccessToken)
  28. if err != nil {
  29. panic(err)
  30. }
  31. claims.AccessToken = token.AccessToken
  32. c.SetSessionClaims(claims)
  33. c.ResponseOk(claims)
  34. }
  35. func (c *ApiController) Signout() {
  36. c.SetSessionClaims(nil)
  37. c.ResponseOk()
  38. }
  39. func (c *ApiController) GetAccount() {
  40. if c.RequireSignedIn() {
  41. return
  42. }
  43. claims := c.GetSessionClaims()
  44. c.ResponseOk(claims)
  45. }

No Description

Contributors (1)