mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-23 02:35:49 +08:00
Fix JWT token bugs.
This commit is contained in:
parent
f014554415
commit
df948e9e34
@ -34,7 +34,7 @@ type Token struct {
|
||||
Application string `xorm:"varchar(100)" json:"application"`
|
||||
|
||||
Code string `xorm:"varchar(100)" json:"code"`
|
||||
AccessToken string `xorm:"varchar(100)" json:"accessToken"`
|
||||
AccessToken string `xorm:"mediumtext" json:"accessToken"`
|
||||
ExpiresIn int `json:"expiresIn"`
|
||||
Scope string `xorm:"varchar(100)" json:"scope"`
|
||||
TokenType string `xorm:"varchar(100)" json:"tokenType"`
|
||||
|
@ -20,12 +20,14 @@ import (
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
)
|
||||
|
||||
var jwtSecret = []byte("aaa")
|
||||
var jwtSecret = []byte("CasdoorSecret")
|
||||
|
||||
type Claims struct {
|
||||
Username string `json:"username"`
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
Organization string `json:"organization"`
|
||||
Username string `json:"username"`
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
IsAdmin bool `json:"isAdmin"`
|
||||
jwt.StandardClaims
|
||||
}
|
||||
|
||||
@ -34,9 +36,11 @@ func generateJwtToken(application *Application, user *User) (string, error) {
|
||||
expireTime := nowTime.Add(time.Duration(application.ExpireInHours) * time.Hour)
|
||||
|
||||
claims := Claims{
|
||||
Username: user.Name,
|
||||
Name: user.DisplayName,
|
||||
Email: user.Email,
|
||||
Organization: user.Owner,
|
||||
Username: user.Name,
|
||||
Name: user.DisplayName,
|
||||
Email: user.Email,
|
||||
IsAdmin: user.IsAdmin,
|
||||
StandardClaims: jwt.StandardClaims{
|
||||
Audience: application.ClientId,
|
||||
ExpiresAt: expireTime.Unix(),
|
||||
|
@ -8,6 +8,7 @@
|
||||
"@testing-library/react": "^9.3.2",
|
||||
"@testing-library/user-event": "^7.1.2",
|
||||
"antd": "^4.7.2",
|
||||
"copy-to-clipboard": "^3.3.1",
|
||||
"i18next": "^19.8.9",
|
||||
"moment": "^2.29.1",
|
||||
"react": "^16.14.0",
|
||||
|
@ -17,6 +17,7 @@ import React from "react";
|
||||
import {isMobile as isMobileDevice} from "react-device-detect";
|
||||
import "./i18n";
|
||||
import i18next from "i18next";
|
||||
import copy from "copy-to-clipboard";
|
||||
|
||||
export let ServerUrl = "";
|
||||
|
||||
@ -151,3 +152,14 @@ export function changeLanguage(language) {
|
||||
i18next.changeLanguage(language)
|
||||
window.location.reload(true);
|
||||
}
|
||||
|
||||
export function getClickable(text) {
|
||||
return (
|
||||
<a onClick={() => {
|
||||
copy(text);
|
||||
showMessage("success", `Copied to clipboard`);
|
||||
}}>
|
||||
{text}
|
||||
</a>
|
||||
)
|
||||
}
|
||||
|
@ -130,6 +130,9 @@ class TokenListPage extends React.Component {
|
||||
key: 'code',
|
||||
// width: '150px',
|
||||
sorter: (a, b) => a.code.localeCompare(b.code),
|
||||
render: (text, record, index) => {
|
||||
return Setting.getClickable(text);
|
||||
}
|
||||
},
|
||||
{
|
||||
title: i18next.t("token:Access Token"),
|
||||
@ -137,6 +140,10 @@ class TokenListPage extends React.Component {
|
||||
key: 'accessToken',
|
||||
// width: '150px',
|
||||
sorter: (a, b) => a.accessToken.localeCompare(b.accessToken),
|
||||
ellipsis: true,
|
||||
render: (text, record, index) => {
|
||||
return Setting.getClickable(text);
|
||||
}
|
||||
},
|
||||
{
|
||||
title: i18next.t("token:Expires In"),
|
||||
|
@ -3387,6 +3387,13 @@ copy-to-clipboard@^3.2.0:
|
||||
dependencies:
|
||||
toggle-selection "^1.0.6"
|
||||
|
||||
copy-to-clipboard@^3.3.1:
|
||||
version "3.3.1"
|
||||
resolved "https://registry.npmjs.org/copy-to-clipboard/-/copy-to-clipboard-3.3.1.tgz#115aa1a9998ffab6196f93076ad6da3b913662ae"
|
||||
integrity sha512-i13qo6kIHTTpCm8/Wup+0b1mVWETvu2kIMzKoK8FpkLkFxlt0znUAHcMzox+T8sPlqtZXq3CulEjQHsYiGFJUw==
|
||||
dependencies:
|
||||
toggle-selection "^1.0.6"
|
||||
|
||||
core-js-compat@^3.6.2:
|
||||
version "3.6.5"
|
||||
resolved "https://registry.npm.taobao.org/core-js-compat/download/core-js-compat-3.6.5.tgz#2a51d9a4e25dfd6e690251aa81f99e3c05481f1c"
|
||||
|
Loading…
x
Reference in New Issue
Block a user