Compare commits

...

7 Commits

Author SHA1 Message Date
Will.Feng
2c4b1093ed fix: Correct expiresIn calculation for WeChat Mini Program token. (#2814) 2024-03-17 22:20:21 +08:00
Yang Luo
d1c55d5aa7 fix: improve error message in token_cas.go 2024-03-17 22:01:49 +08:00
SamYSF
c8aa35c9c6 feat: add token to the page for Chrome extension (#2804)
* feat: add token to the page for Chrome extension

* Update token_oauth.go

---------

Co-authored-by: Eric Luo <hsluoyz@qq.com>
2024-03-17 22:01:28 +08:00
Yang Luo
6037f37b87 feat: add default token format for built-in app 2024-03-17 20:46:01 +08:00
Yang Luo
1b478903d8 feat: fix login page error cannot show bug 2024-03-17 11:39:12 +08:00
Yang Luo
4f5ac7a10b Fix Face IDs label 2024-03-17 09:56:24 +08:00
Yang Luo
e81ba62234 Improve Face ID signin method UI 2024-03-17 09:56:23 +08:00
37 changed files with 112 additions and 33 deletions

View File

@@ -307,6 +307,7 @@ func (c *ApiController) Logout() {
}
c.ClearUserSession()
c.ClearTokenSession()
owner, username := util.GetOwnerAndNameFromId(user)
_, err := object.DeleteSessionId(util.GetSessionId(owner, username, object.CasdoorApplication), c.Ctx.Input.CruSession.SessionID())
if err != nil {
@@ -353,6 +354,7 @@ func (c *ApiController) Logout() {
}
c.ClearUserSession()
c.ClearTokenSession()
// TODO https://github.com/casdoor/casdoor/pull/1494#discussion_r1095675265
owner, username := util.GetOwnerAndNameFromId(user)
@@ -433,6 +435,17 @@ func (c *ApiController) GetAccount() {
return
}
token := c.GetSessionToken()
if token == nil {
token, err = object.GetTokenForExtension(user, c.Ctx.Request.Host)
if err != nil {
c.ResponseError(err.Error())
return
}
c.SetSessionToken(token)
}
u.AccessToken = token.AccessToken
resp := Response{
Status: "ok",
Sub: user.Id,

View File

@@ -122,6 +122,17 @@ func (c *ApiController) GetSessionUsername() string {
return user.(string)
}
func (c *ApiController) GetSessionToken() *object.Token {
tokenValue := c.GetSession("token")
var token *object.Token
var ok bool
if token, ok = tokenValue.(*object.Token); !ok {
token = nil
}
return token
}
func (c *ApiController) GetSessionApplication() *object.Application {
clientId := c.GetSession("aud")
if clientId == nil {
@@ -141,6 +152,10 @@ func (c *ApiController) ClearUserSession() {
c.SetSessionData(nil)
}
func (c *ApiController) ClearTokenSession() {
c.SetSessionToken(nil)
}
func (c *ApiController) GetSessionOidc() (string, string) {
sessionData := c.GetSessionData()
if sessionData != nil &&
@@ -167,6 +182,10 @@ func (c *ApiController) SetSessionUsername(user string) {
c.SetSession("username", user)
}
func (c *ApiController) SetSessionToken(token *object.Token) {
c.SetSession("token", token)
}
// GetSessionData ...
func (c *ApiController) GetSessionData() *SessionData {
session := c.GetSession("SessionData")

View File

@@ -110,6 +110,11 @@
"name": "WebAuthn",
"displayName": "WebAuthn",
"rule": "None"
},
{
"name": "Face ID",
"displayName": "Face ID",
"rule": "None"
}
],
"signupItems": [
@@ -179,8 +184,10 @@
"refresh_token"
],
"redirectUris": [
""
"http://localhost:9000/callback"
],
"tokenFormat": "JWT",
"tokenFields": [],
"expireInHours": 168,
"failedSigninLimit": 5,
"failedSigninFrozenTime": 15

View File

@@ -311,6 +311,9 @@ func extendApplicationWithSigninMethods(application *Application) (err error) {
signinMethod := &SigninMethod{Name: "WebAuthn", DisplayName: "WebAuthn", Rule: "None"}
application.SigninMethods = append(application.SigninMethods, signinMethod)
}
signinMethod := &SigninMethod{Name: "Face ID", DisplayName: "Face ID", Rule: "None"}
application.SigninMethods = append(application.SigninMethods, signinMethod)
}
if len(application.SigninMethods) == 0 {

View File

@@ -45,6 +45,7 @@ func InitDb() {
}
initWebAuthn()
initToken()
}
func getBuiltInAccountItems() []*AccountItem {
@@ -184,6 +185,7 @@ func initBuiltInApplication() {
{Name: "Password", DisplayName: "Password", Rule: "All"},
{Name: "Verification code", DisplayName: "Verification code", Rule: "All"},
{Name: "WebAuthn", DisplayName: "WebAuthn", Rule: "None"},
{Name: "Face ID", DisplayName: "Face ID", Rule: "None"},
},
SignupItems: []*SignupItem{
{Name: "ID", Visible: false, Required: true, Prompted: false, Rule: "Random"},
@@ -197,6 +199,7 @@ func initBuiltInApplication() {
},
Tags: []string{},
RedirectUris: []string{},
TokenFormat: "JWT",
TokenFields: []string{},
ExpireInHours: 168,
FormOffset: 2,
@@ -307,6 +310,10 @@ func initWebAuthn() {
gob.Register(webauthn.SessionData{})
}
func initToken() {
gob.Register(&Token{})
}
func initBuiltInUserModel() {
model, err := GetModel("built-in/user-model-built-in")
if err != nil {

View File

@@ -261,7 +261,7 @@ func GetValidationBySaml(samlRequest string, host string) (string, string, error
ok, _, service, userId := GetCasTokenByTicket(ticket)
if !ok {
return "", "", fmt.Errorf("ticket %s found", ticket)
return "", "", fmt.Errorf("the CAS token for ticket %s is not found", ticket)
}
user, err := GetUser(userId)
@@ -270,7 +270,7 @@ func GetValidationBySaml(samlRequest string, host string) (string, string, error
}
if user == nil {
return "", "", fmt.Errorf("user %s found", userId)
return "", "", fmt.Errorf("the user %s is not found", userId)
}
application, err := GetApplicationByUser(user)
@@ -279,7 +279,7 @@ func GetValidationBySaml(samlRequest string, host string) (string, string, error
}
if application == nil {
return "", "", fmt.Errorf("application for user %s found", userId)
return "", "", fmt.Errorf("the application for user %s is not found", userId)
}
samlResponse, err := NewSamlResponse11(user, request.RequestID, host)

View File

@@ -715,7 +715,7 @@ func GetWechatMiniProgramToken(application *Application, code string, host strin
Code: session.SessionKey, // a trick, because miniprogram does not use the code, so use the code field to save the session_key
AccessToken: accessToken,
RefreshToken: refreshToken,
ExpiresIn: application.ExpireInHours * 60,
ExpiresIn: application.ExpireInHours * hourSeconds,
Scope: "",
TokenType: "Bearer",
CodeIsUsed: true,
@@ -726,3 +726,19 @@ func GetWechatMiniProgramToken(application *Application, code string, host strin
}
return token, nil, nil
}
func GetTokenForExtension(user *User, host string) (*Token, error) {
application, err := GetApplicationByUser(user)
if err != nil {
return nil, err
}
if application == nil {
return nil, fmt.Errorf("the application for user %s is not found", user.Id)
}
token, err := GetTokenByUser(application, user, "profile", "", host)
if err != nil {
return nil, err
}
return token, nil
}

View File

@@ -98,6 +98,7 @@ type User struct {
PreHash string `xorm:"varchar(100)" json:"preHash"`
AccessKey string `xorm:"varchar(100)" json:"accessKey"`
AccessSecret string `xorm:"varchar(100)" json:"accessSecret"`
AccessToken string `xorm:"mediumtext" json:"accessToken"`
CreatedIp string `xorm:"varchar(100)" json:"createdIp"`
LastSigninTime string `xorm:"varchar(100)" json:"lastSigninTime"`

View File

@@ -51,6 +51,7 @@ class App extends Component {
classes: props,
selectedMenuKey: 0,
account: undefined,
accessToken: undefined,
uri: null,
themeAlgorithm: storageThemeAlgorithm,
themeData: Conf.ThemeDefault,
@@ -228,9 +229,11 @@ class App extends Component {
AuthBackend.getAccount(query)
.then((res) => {
let account = null;
let accessToken = null;
if (res.status === "ok") {
account = res.data;
account.organization = res.data2;
accessToken = res.data.accessToken;
this.setLanguage(account);
this.setTheme(Setting.getThemeData(account.organization), Conf.InitThemeAlgorithm);
@@ -242,6 +245,7 @@ class App extends Component {
this.setState({
account: account,
accessToken: accessToken,
});
});
}
@@ -256,6 +260,7 @@ class App extends Component {
return (
<React.Fragment>
{!this.state.account ? null : <div style={{display: "none"}} id="CasdoorApplicationName" value={this.state.account.signupApplication} />}
{!this.state.account ? null : <div style={{display: "none"}} id="CasdoorAccessToken" value={this.state.accessToken} />}
<Footer id="footer" style={
{
textAlign: "center",

View File

@@ -50,6 +50,7 @@ class ApplicationListPage extends BaseListPage {
{name: "Password", displayName: "Password", rule: "All"},
{name: "Verification code", displayName: "Verification code", rule: "All"},
{name: "WebAuthn", displayName: "WebAuthn", rule: "None"},
{name: "Face ID", displayName: "Face ID", rule: "None"},
],
signupItems: [
{name: "ID", visible: false, required: true, rule: "Random"},

View File

@@ -71,7 +71,9 @@ class EntryPage extends React.Component {
this.props.updataThemeData(themeData);
this.props.updateApplication(application);
localStorage.setItem("applicationName", application.name);
if (application) {
localStorage.setItem("applicationName", application.name);
}
};
const onUpdatePricing = (pricing) => {

View File

@@ -980,11 +980,11 @@ class UserEditPage extends React.Component {
return (
<Row style={{marginTop: "20px"}} >
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
{Setting.getLabel(i18next.t("user:Face ids"), i18next.t("user:Face ids"))} :
{Setting.getLabel(i18next.t("user:Face IDs"), i18next.t("user:Face IDs"))} :
</Col>
<Col span={22} >
<FaceIdTable
title={i18next.t("user:Face ids")}
title={i18next.t("user:Face IDs")}
table={this.state.user.faceIds}
onUpdateTable={(table) => {this.updateUserField("faceIds", table);}}
/>

View File

@@ -1066,7 +1066,12 @@ class LoginPage extends React.Component {
application?.signinMethods?.forEach((signinMethod) => {
const item = itemsMap.get(generateItemKey(signinMethod.name, signinMethod.rule));
if (item) {
const label = signinMethod.name === signinMethod.displayName ? item.label : signinMethod.displayName;
let label = signinMethod.name === signinMethod.displayName ? item.label : signinMethod.displayName;
if (application?.signinMethods?.length >= 4 && label === "Verification code") {
label = "Code";
}
items.push({label: label, key: item.key});
}
});

View File

@@ -1081,7 +1081,7 @@
"Email/phone reset successfully": "Email/phone reset successfully",
"Empty input!": "Empty input!",
"Face ID": "Face ID",
"Face ids": "Face ids",
"Face IDs": "Face IDs",
"Gender": "Gender",
"Gender - Tooltip": "Gender - Tooltip",
"Homepage": "Homepage",

View File

@@ -1081,7 +1081,7 @@
"Email/phone reset successfully": "E-Mail-/Telefon-Zurücksetzung erfolgreich durchgeführt",
"Empty input!": "Leere Eingabe!",
"Face ID": "Face ID",
"Face ids": "Face ids",
"Face IDs": "Face IDs",
"Gender": "Gender",
"Gender - Tooltip": "Gender - Tooltip",
"Homepage": "Startseite des Benutzers",

View File

@@ -1081,7 +1081,7 @@
"Email/phone reset successfully": "Email/phone reset successfully",
"Empty input!": "Empty input!",
"Face ID": "Face ID",
"Face ids": "Face ids",
"Face IDs": "Face IDs",
"Gender": "Gender",
"Gender - Tooltip": "Gender - Tooltip",
"Homepage": "Homepage",

View File

@@ -1081,7 +1081,7 @@
"Email/phone reset successfully": "Restablecimiento de correo electrónico/teléfono exitoso",
"Empty input!": "¡Entrada vacía!",
"Face ID": "Face ID",
"Face ids": "Face ids",
"Face IDs": "Face IDs",
"Gender": "Gender",
"Gender - Tooltip": "Gender - Tooltip",
"Homepage": "Página de inicio del usuario",

View File

@@ -1081,7 +1081,7 @@
"Email/phone reset successfully": "Email/phone reset successfully",
"Empty input!": "Empty input!",
"Face ID": "Face ID",
"Face ids": "Face ids",
"Face IDs": "Face IDs",
"Gender": "Gender",
"Gender - Tooltip": "Gender - Tooltip",
"Homepage": "Homepage",

View File

@@ -1081,7 +1081,7 @@
"Email/phone reset successfully": "Email/phone reset successfully",
"Empty input!": "Empty input!",
"Face ID": "Face ID",
"Face ids": "Face ids",
"Face IDs": "Face IDs",
"Gender": "Gender",
"Gender - Tooltip": "Gender - Tooltip",
"Homepage": "Homepage",

View File

@@ -1081,7 +1081,7 @@
"Email/phone reset successfully": "E-mail ou téléphone réinitialisé avec succès",
"Empty input!": "Champ vide !",
"Face ID": "Face ID",
"Face ids": "Face ids",
"Face IDs": "Face IDs",
"Gender": "Genre",
"Gender - Tooltip": "Genre - Infobulle",
"Homepage": "Site web",

View File

@@ -1081,7 +1081,7 @@
"Email/phone reset successfully": "Email/phone reset successfully",
"Empty input!": "Empty input!",
"Face ID": "Face ID",
"Face ids": "Face ids",
"Face IDs": "Face IDs",
"Gender": "Gender",
"Gender - Tooltip": "Gender - Tooltip",
"Homepage": "Homepage",

View File

@@ -1081,7 +1081,7 @@
"Email/phone reset successfully": "Email/telepon berhasil diatur ulang",
"Empty input!": "Masukan kosong!",
"Face ID": "Face ID",
"Face ids": "Face ids",
"Face IDs": "Face IDs",
"Gender": "Gender",
"Gender - Tooltip": "Gender - Tooltip",
"Homepage": "Homepage",

View File

@@ -1081,7 +1081,7 @@
"Email/phone reset successfully": "Email/phone reset successfully",
"Empty input!": "Empty input!",
"Face ID": "Face ID",
"Face ids": "Face ids",
"Face IDs": "Face IDs",
"Gender": "Gender",
"Gender - Tooltip": "Gender - Tooltip",
"Homepage": "Homepage",

View File

@@ -1081,7 +1081,7 @@
"Email/phone reset successfully": "メール/電話のリセットが成功しました",
"Empty input!": "空の入力!",
"Face ID": "Face ID",
"Face ids": "Face ids",
"Face IDs": "Face IDs",
"Gender": "Gender",
"Gender - Tooltip": "Gender - Tooltip",
"Homepage": "ユーザーのホームページ",

View File

@@ -1081,7 +1081,7 @@
"Email/phone reset successfully": "Email/phone reset successfully",
"Empty input!": "Empty input!",
"Face ID": "Face ID",
"Face ids": "Face ids",
"Face IDs": "Face IDs",
"Gender": "Gender",
"Gender - Tooltip": "Gender - Tooltip",
"Homepage": "Homepage",

View File

@@ -1081,7 +1081,7 @@
"Email/phone reset successfully": "이메일/전화 초기화가 성공적으로 완료되었습니다",
"Empty input!": "빈 입력!",
"Face ID": "Face ID",
"Face ids": "Face ids",
"Face IDs": "Face IDs",
"Gender": "Gender",
"Gender - Tooltip": "Gender - Tooltip",
"Homepage": "사용자의 홈페이지",

View File

@@ -1081,7 +1081,7 @@
"Email/phone reset successfully": "Email/phone reset successfully",
"Empty input!": "Empty input!",
"Face ID": "Face ID",
"Face ids": "Face ids",
"Face IDs": "Face IDs",
"Gender": "Gender",
"Gender - Tooltip": "Gender - Tooltip",
"Homepage": "Homepage",

View File

@@ -1081,7 +1081,7 @@
"Email/phone reset successfully": "Email/phone reset successfully",
"Empty input!": "Empty input!",
"Face ID": "Face ID",
"Face ids": "Face ids",
"Face IDs": "Face IDs",
"Gender": "Gender",
"Gender - Tooltip": "Gender - Tooltip",
"Homepage": "Homepage",

View File

@@ -1081,7 +1081,7 @@
"Email/phone reset successfully": "Email/phone reset successfully",
"Empty input!": "Empty input!",
"Face ID": "Face ID",
"Face ids": "Face ids",
"Face IDs": "Face IDs",
"Gender": "Gender",
"Gender - Tooltip": "Gender - Tooltip",
"Homepage": "Homepage",

View File

@@ -1081,7 +1081,7 @@
"Email/phone reset successfully": "Redefinição de e-mail/telefone com sucesso",
"Empty input!": "Entrada vazia!",
"Face ID": "Face ID",
"Face ids": "Face ids",
"Face IDs": "Face IDs",
"Gender": "Gênero",
"Gender - Tooltip": "Gênero - Tooltip",
"Homepage": "Página inicial",

View File

@@ -1081,7 +1081,7 @@
"Email/phone reset successfully": "Электронная почта / номер телефона успешно сброшены",
"Empty input!": "Пустой ввод!",
"Face ID": "Face ID",
"Face ids": "Face ids",
"Face IDs": "Face IDs",
"Gender": "Gender",
"Gender - Tooltip": "Gender - Tooltip",
"Homepage": "Главная страница пользователя",

View File

@@ -1081,7 +1081,7 @@
"Email/phone reset successfully": "Email/phone reset successfully",
"Empty input!": "Empty input!",
"Face ID": "Face ID",
"Face ids": "Face ids",
"Face IDs": "Face IDs",
"Gender": "Gender",
"Gender - Tooltip": "Gender - Tooltip",
"Homepage": "Homepage",

View File

@@ -1081,7 +1081,7 @@
"Email/phone reset successfully": "Email/phone reset successfully",
"Empty input!": "Empty input!",
"Face ID": "Face ID",
"Face ids": "Face ids",
"Face IDs": "Face IDs",
"Gender": "Gender",
"Gender - Tooltip": "Gender - Tooltip",
"Homepage": "Homepage",

View File

@@ -1081,7 +1081,7 @@
"Email/phone reset successfully": "Email/phone reset successfully",
"Empty input!": "Empty input!",
"Face ID": "Face ID",
"Face ids": "Face ids",
"Face IDs": "Face IDs",
"Gender": "Gender",
"Gender - Tooltip": "Gender - Tooltip",
"Homepage": "Homepage",

View File

@@ -1081,7 +1081,7 @@
"Email/phone reset successfully": "Đặt lại email/điện thoại thành công",
"Empty input!": "Đầu vào trống!",
"Face ID": "Face ID",
"Face ids": "Face ids",
"Face IDs": "Face IDs",
"Gender": "Gender",
"Gender - Tooltip": "Gender - Tooltip",
"Homepage": "Trang chủ của người dùng",

View File

@@ -1081,7 +1081,7 @@
"Email/phone reset successfully": "邮箱或手机号重置成功",
"Empty input!": "输入为空!",
"Face ID": "Face ID",
"Face ids": "Face ids",
"Face IDs": "Face IDs",
"Gender": "性别",
"Gender - Tooltip": "性别 - Tooltip",
"Homepage": "个人主页",

View File

@@ -96,7 +96,7 @@ class FaceIdTable extends React.Component {
<Table scroll={{x: "max-content"}} columns={columns} dataSource={this.props.table} size="middle" bordered pagination={false}
title={() => (
<div>
{i18next.t("user:Face ids")}&nbsp;&nbsp;&nbsp;&nbsp;
{i18next.t("user:Face IDs")}&nbsp;&nbsp;&nbsp;&nbsp;
<Button disabled={this.props.table?.length >= 5} style={{marginRight: "5px"}} type="primary" size="small" onClick={() => this.setState({openFaceRecognitionModal: true})}>
{i18next.t("general:Add Face Id")}
</Button>