token.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package model
  2. import (
  3. "github.com/golang-jwt/jwt"
  4. "iot_manager_service/app/system/dao"
  5. )
  6. type JwtToken struct {
  7. jwt.StandardClaims
  8. TenantId string `json:"tenant_id"`
  9. UserId int64 `json:"user_id"`
  10. TokenType string `json:"token_type"`
  11. ClientId string `json:"client_id"`
  12. RoleId string `json:"role_id"`
  13. RoleName string `json:"role_name"`
  14. DeptId string `json:"dept_id"`
  15. PostId string `json:"post_id"`
  16. OauthId string `json:"oauth_id"`
  17. Account string `json:"account"`
  18. UserName string `json:"user_name"`
  19. NickName string `json:"nick_name"`
  20. Random string `json:"random"`
  21. }
  22. type Token struct {
  23. TenantId string
  24. UserName string
  25. Password string
  26. GrantType string
  27. RefreshToken string
  28. UserType string
  29. }
  30. type UserInfo struct {
  31. dao.User //用户基础信息
  32. Permissions []string //权限标识集合
  33. Roles []string //角色集合
  34. OauthId string //第三方授权id
  35. }
  36. type RspToken struct {
  37. TenantId string `json:"tenant_id"`
  38. UserId string `json:"user_id"`
  39. DeptId string `json:"dept_id"`
  40. PostId string `json:"post_id"`
  41. RoleId string `json:"role_id"`
  42. OauthId string `json:"oauth_id"`
  43. Account string `json:"account"`
  44. UserName string `json:"user_name"`
  45. NickName string `json:"nick_name"`
  46. RoleName string `json:"role_name"`
  47. Avatar string `json:"avatar"`
  48. AccessToken string `json:"access_token"`
  49. RefreshToken string `json:"refresh_token"`
  50. TokenType string `json:"token_type"`
  51. ExpiresIn int `json:"expires_in"`
  52. License string `json:"license"`
  53. }
  54. type RspCaptcha struct {
  55. Key string `json:"key"`
  56. Image string `json:"image"`
  57. }
  58. type RspLogin struct {
  59. ID string `json:"id"`
  60. Name string `json:"name"`
  61. BackgroundUrl string `json:"backgroundUrl"`
  62. SysLogoUrl string `json:"sysLogoUrl"`
  63. }
  64. // JWT
  65. const (
  66. Iss = "iss"
  67. Aud = "aud"
  68. TenantId = "tenant_id"
  69. RoleName = "role_name"
  70. PostId = "post_id"
  71. UserId = "user_id"
  72. RoleId = "role_id"
  73. UserName = "user_name"
  74. OauthID = "oauth_id"
  75. NickName = "nick_name"
  76. TokenType = "token_type"
  77. DeptId = "dept_id"
  78. Account = "account"
  79. ClientId = "client_id"
  80. Exp = "exp"
  81. Nbf = "nbf"
  82. BEARER = "bearer"
  83. )
  84. const (
  85. AdminTenantId = "1000000000000000" //默认租户
  86. DES_KEY = "0000000000000000" //租户授权码默认16位密钥
  87. )
  88. const (
  89. CaptchaHeaderKey = "Captcha-Key"
  90. CaptchaHeaderCode = "Captcha-Code"
  91. CaptchaNotCorrect = "验证码不正确"
  92. UserTypeHeaderKey = "User-Type"
  93. UserNotFound = "用户名或密码错误"
  94. UserHasNoRole = "未获得用户的角色信息"
  95. TenantNotFound = "请输入专属登录地址!"
  96. UserHasNoTenant = "未获得用户的租户信息"
  97. UserHasNoTenantPermission = "租户授权已过期,请联系管理员"
  98. HeaderKey = "Authorization"
  99. HEADER_PREFIX = "Basic "
  100. DEFAULT_AVATAR = "https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png"
  101. )