diff --git a/object/token.go b/object/token.go index 81fe5bee..5336b0d2 100644 --- a/object/token.go +++ b/object/token.go @@ -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"` diff --git a/object/token_jwt.go b/object/token_jwt.go index 4a389c05..989db7a8 100644 --- a/object/token_jwt.go +++ b/object/token_jwt.go @@ -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(), diff --git a/web/package.json b/web/package.json index 253a17b8..e80bb06c 100644 --- a/web/package.json +++ b/web/package.json @@ -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", diff --git a/web/src/Setting.js b/web/src/Setting.js index bbda2333..3f01ceca 100644 --- a/web/src/Setting.js +++ b/web/src/Setting.js @@ -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 ( + { + copy(text); + showMessage("success", `Copied to clipboard`); + }}> + {text} + + ) +} diff --git a/web/src/TokenListPage.js b/web/src/TokenListPage.js index 94b03623..8f576f15 100644 --- a/web/src/TokenListPage.js +++ b/web/src/TokenListPage.js @@ -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"), diff --git a/web/yarn.lock b/web/yarn.lock index a733ec2b..9ebab453 100644 --- a/web/yarn.lock +++ b/web/yarn.lock @@ -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"