Compare commits

...

5 Commits

Author SHA1 Message Date
zzjin
9c8ea027ef feat: add the missing userId param docs for get-user API (#1698)
* Add roles to SAML response

* Fix: Add back missing get-user userId param doc.

Signed-off-by: zzjin <tczzjin@gmail.com>

* Update user.go

---------

Signed-off-by: zzjin <tczzjin@gmail.com>
Co-authored-by: Yang Luo <hsluoyz@qq.com>
2023-03-30 18:39:14 +08:00
Yang Luo
aaa56d3354 Add roles to SAML response 2023-03-30 14:43:34 +08:00
Yaodong Yu
b45c49d3a4 feat: fix incorrect preferred_username field mapping in OIDC (#1697) 2023-03-29 22:18:12 +08:00
Yaodong Yu
5b3202cc89 feat: fix phone validation bug in signup page (#1693) 2023-03-27 22:52:49 +08:00
Gucheng Wang
5280f872dc Speed up GetOAuthToken() 2023-03-27 14:05:44 +08:00
8 changed files with 39 additions and 16 deletions

View File

@@ -84,6 +84,7 @@ func (c *ApiController) GetUsers() {
// @Param owner query string false "The owner of the user"
// @Param email query string false "The email of the user"
// @Param phone query string false "The phone of the user"
// @Param userId query string false "The userId of the user"
// @Success 200 {object} object.User The Response object
// @router /get-user [get]
func (c *ApiController) GetUser() {

View File

@@ -108,8 +108,8 @@ func (idp *CasdoorIdProvider) GetToken(code string) (*oauth2.Token, error) {
type CasdoorUserInfo struct {
Id string `json:"sub"`
Name string `json:"name"`
DisplayName string `json:"preferred_username"`
Name string `json:"preferred_username,omitempty"`
DisplayName string `json:"name"`
Email string `json:"email"`
AvatarUrl string `json:"picture"`
Status string `json:"status"`

View File

@@ -61,8 +61,8 @@ func (idp *CustomIdProvider) GetToken(code string) (*oauth2.Token, error) {
type CustomUserInfo struct {
Id string `json:"sub"`
Name string `json:"name"`
DisplayName string `json:"preferred_username"`
Name string `json:"preferred_username,omitempty"`
DisplayName string `json:"name"`
Email string `json:"email"`
AvatarUrl string `json:"picture"`
Status string `json:"status"`

View File

@@ -86,19 +86,30 @@ func NewSamlResponse(user *User, host string, certificate string, destination st
authnStatement.CreateElement("saml:AuthnContext").CreateElement("saml:AuthnContextClassRef").SetText("urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport")
attributes := assertion.CreateElement("saml:AttributeStatement")
email := attributes.CreateElement("saml:Attribute")
email.CreateAttr("Name", "Email")
email.CreateAttr("NameFormat", "urn:oasis:names:tc:SAML:2.0:attrname-format:basic")
email.CreateElement("saml:AttributeValue").CreateAttr("xsi:type", "xs:string").Element().SetText(user.Email)
name := attributes.CreateElement("saml:Attribute")
name.CreateAttr("Name", "Name")
name.CreateAttr("NameFormat", "urn:oasis:names:tc:SAML:2.0:attrname-format:basic")
name.CreateElement("saml:AttributeValue").CreateAttr("xsi:type", "xs:string").Element().SetText(user.Name)
displayName := attributes.CreateElement("saml:Attribute")
displayName.CreateAttr("Name", "DisplayName")
displayName.CreateAttr("NameFormat", "urn:oasis:names:tc:SAML:2.0:attrname-format:basic")
displayName.CreateElement("saml:AttributeValue").CreateAttr("xsi:type", "xs:string").Element().SetText(user.DisplayName)
roles := attributes.CreateElement("saml:Attribute")
roles.CreateAttr("Name", "Roles")
roles.CreateAttr("NameFormat", "urn:oasis:names:tc:SAML:2.0:attrname-format:basic")
ExtendUserWithRolesAndPermissions(user)
for _, role := range user.Roles {
roles.CreateElement("saml:AttributeValue").CreateAttr("xsi:type", "xs:string").Element().SetText(role.Name)
}
return samlResponse, nil
}

View File

@@ -51,7 +51,7 @@ type Token struct {
Organization string `xorm:"varchar(100)" json:"organization"`
User string `xorm:"varchar(100)" json:"user"`
Code string `xorm:"varchar(100)" json:"code"`
Code string `xorm:"varchar(100) index" json:"code"`
AccessToken string `xorm:"mediumtext" json:"accessToken"`
RefreshToken string `xorm:"mediumtext" json:"refreshToken"`
ExpiresIn int `json:"expiresIn"`
@@ -362,7 +362,8 @@ func GetOAuthToken(grantType string, clientId string, clientSecret string, code
}
token.CodeIsUsed = true
updateUsedByCode(token)
go updateUsedByCode(token)
tokenWrapper := &TokenWrapper{
AccessToken: token.AccessToken,
IdToken: token.AccessToken,

View File

@@ -2171,6 +2171,12 @@
"name": "phone",
"description": "The phone of the user",
"type": "string"
},
{
"in": "query",
"name": "userId",
"description": "The userId of the user",
"type": "string"
}
],
"responses": {
@@ -3638,11 +3644,11 @@
}
},
"definitions": {
"2306.0xc0000a7410.false": {
"2306.0xc0003a4480.false": {
"title": "false",
"type": "object"
},
"2340.0xc0000a7440.false": {
"2340.0xc0003a44b0.false": {
"title": "false",
"type": "object"
},
@@ -3776,10 +3782,10 @@
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/2306.0xc0000a7410.false"
"$ref": "#/definitions/2306.0xc0003a4480.false"
},
"data2": {
"$ref": "#/definitions/2340.0xc0000a7440.false"
"$ref": "#/definitions/2340.0xc0003a44b0.false"
},
"msg": {
"type": "string"

View File

@@ -1417,6 +1417,10 @@ paths:
name: phone
description: The phone of the user
type: string
- in: query
name: userId
description: The userId of the user
type: string
responses:
"200":
description: The Response object
@@ -2381,10 +2385,10 @@ paths:
schema:
$ref: '#/definitions/Response'
definitions:
2306.0xc0000a7410.false:
2306.0xc0003a4480.false:
title: "false"
type: object
2340.0xc0000a7440.false:
2340.0xc0003a44b0.false:
title: "false"
type: object
LaravelResponse:
@@ -2476,9 +2480,9 @@ definitions:
type: object
properties:
data:
$ref: '#/definitions/2306.0xc0000a7410.false'
$ref: '#/definitions/2306.0xc0003a4480.false'
data2:
$ref: '#/definitions/2340.0xc0000a7440.false'
$ref: '#/definitions/2340.0xc0003a44b0.false'
msg:
type: string
name:

View File

@@ -386,11 +386,11 @@ class SignupPage extends React.Component {
},
({getFieldValue}) => ({
validator: (_, value) => {
if (!required && value === "") {
if (!required && !value) {
return Promise.resolve();
}
if (value !== "" && !Setting.isValidPhone(value, getFieldValue("countryCode"))) {
if (value && !Setting.isValidPhone(value, getFieldValue("countryCode"))) {
this.setState({validPhone: false});
return Promise.reject(i18next.t("signup:The input is not valid Phone!"));
}