mirror of
https://github.com/casdoor/casdoor.git
synced 2025-08-13 09:37:46 +08:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
8819a8697b | ||
![]() |
85cb68eb66 | ||
![]() |
b25b5f0249 | ||
![]() |
947dcf6e75 | ||
![]() |
113c27db73 | ||
![]() |
badfe34755 |
@@ -282,17 +282,15 @@ func (c *ApiController) Logout() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
affected, application, token, err := object.ExpireTokenByAccessToken(accessToken)
|
_, application, token, err := object.ExpireTokenByAccessToken(accessToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.ResponseError(err.Error())
|
c.ResponseError(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if token == nil {
|
||||||
if !affected {
|
|
||||||
c.ResponseError(c.T("token:Token not found, invalid accessToken"))
|
c.ResponseError(c.T("token:Token not found, invalid accessToken"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if application == nil {
|
if application == nil {
|
||||||
c.ResponseError(fmt.Sprintf(c.T("auth:The application: %s does not exist")), token.Application)
|
c.ResponseError(fmt.Sprintf(c.T("auth:The application: %s does not exist")), token.Application)
|
||||||
return
|
return
|
||||||
@@ -319,7 +317,15 @@ func (c *ApiController) Logout() {
|
|||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
if application.IsRedirectUriValid(redirectUri) {
|
if application.IsRedirectUriValid(redirectUri) {
|
||||||
c.Ctx.Redirect(http.StatusFound, fmt.Sprintf("%s?state=%s", strings.TrimRight(redirectUri, "/"), state))
|
redirectUrl := redirectUri
|
||||||
|
if state != "" {
|
||||||
|
if strings.Contains(redirectUri, "?") {
|
||||||
|
redirectUrl = fmt.Sprintf("%s&state=%s", strings.TrimSuffix(redirectUri, "/"), state)
|
||||||
|
} else {
|
||||||
|
redirectUrl = fmt.Sprintf("%s?state=%s", strings.TrimSuffix(redirectUri, "/"), state)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c.Ctx.Redirect(http.StatusFound, redirectUrl)
|
||||||
} else {
|
} else {
|
||||||
c.ResponseError(fmt.Sprintf(c.T("token:Redirect URI: %s doesn't exist in the allowed Redirect URI list"), redirectUri))
|
c.ResponseError(fmt.Sprintf(c.T("token:Redirect URI: %s doesn't exist in the allowed Redirect URI list"), redirectUri))
|
||||||
return
|
return
|
||||||
|
@@ -155,7 +155,8 @@ func (c *ApiController) HandleLoggedIn(application *object.Application, user *ob
|
|||||||
resp = &Response{Status: "error", Msg: fmt.Sprintf("error: grant_type: %s is not supported in this application", form.Type), Data: ""}
|
resp = &Response{Status: "error", Msg: fmt.Sprintf("error: grant_type: %s is not supported in this application", form.Type), Data: ""}
|
||||||
} else {
|
} else {
|
||||||
scope := c.Input().Get("scope")
|
scope := c.Input().Get("scope")
|
||||||
token, _ := object.GetTokenByUser(application, user, scope, c.Ctx.Request.Host)
|
nonce := c.Input().Get("nonce")
|
||||||
|
token, _ := object.GetTokenByUser(application, user, scope, nonce, c.Ctx.Request.Host)
|
||||||
resp = tokenToResponse(token)
|
resp = tokenToResponse(token)
|
||||||
}
|
}
|
||||||
} else if form.Type == ResponseTypeSaml { // saml flow
|
} else if form.Type == ResponseTypeSaml { // saml flow
|
||||||
|
@@ -243,7 +243,13 @@ func (c *ApiController) GetAllObjects() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.ResponseOk(object.GetAllObjects(userId))
|
objects, err := object.GetAllObjects(userId)
|
||||||
|
if err != nil {
|
||||||
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.ResponseOk(objects)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ApiController) GetAllActions() {
|
func (c *ApiController) GetAllActions() {
|
||||||
@@ -253,7 +259,13 @@ func (c *ApiController) GetAllActions() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.ResponseOk(object.GetAllActions(userId))
|
actions, err := object.GetAllActions(userId)
|
||||||
|
if err != nil {
|
||||||
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.ResponseOk(actions)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ApiController) GetAllRoles() {
|
func (c *ApiController) GetAllRoles() {
|
||||||
@@ -263,5 +275,11 @@ func (c *ApiController) GetAllRoles() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.ResponseOk(object.GetAllRoles(userId))
|
roles, err := object.GetAllRoles(userId)
|
||||||
|
if err != nil {
|
||||||
|
c.ResponseError(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.ResponseOk(roles)
|
||||||
}
|
}
|
||||||
|
@@ -59,6 +59,7 @@ func (c *ApiController) GetLdapUsers() {
|
|||||||
c.ResponseError(err.Error())
|
c.ResponseError(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
//groupsMap, err := conn.GetLdapGroups(ldapServer.BaseDn)
|
//groupsMap, err := conn.GetLdapGroups(ldapServer.BaseDn)
|
||||||
//if err != nil {
|
//if err != nil {
|
||||||
|
@@ -237,22 +237,28 @@ func checkLdapUserPassword(user *User, password string, lang string) error {
|
|||||||
|
|
||||||
searchResult, err := conn.Conn.Search(searchReq)
|
searchResult, err := conn.Conn.Search(searchReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
conn.Close()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(searchResult.Entries) == 0 {
|
if len(searchResult.Entries) == 0 {
|
||||||
|
conn.Close()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if len(searchResult.Entries) > 1 {
|
if len(searchResult.Entries) > 1 {
|
||||||
|
conn.Close()
|
||||||
return fmt.Errorf(i18n.Translate(lang, "check:Multiple accounts with same uid, please check your ldap server"))
|
return fmt.Errorf(i18n.Translate(lang, "check:Multiple accounts with same uid, please check your ldap server"))
|
||||||
}
|
}
|
||||||
|
|
||||||
hit = true
|
hit = true
|
||||||
dn := searchResult.Entries[0].DN
|
dn := searchResult.Entries[0].DN
|
||||||
if err := conn.Conn.Bind(dn, password); err == nil {
|
if err = conn.Conn.Bind(dn, password); err == nil {
|
||||||
ldapLoginSuccess = true
|
ldapLoginSuccess = true
|
||||||
|
conn.Close()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
conn.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ldapLoginSuccess {
|
if !ldapLoginSuccess {
|
||||||
|
@@ -100,6 +100,7 @@ func (l *LdapAutoSynchronizer) syncRoutine(ldap *Ldap, stopChan chan struct{}) e
|
|||||||
|
|
||||||
users, err := conn.GetLdapUsers(ldap)
|
users, err := conn.GetLdapUsers(ldap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
conn.Close()
|
||||||
logs.Warning(fmt.Sprintf("autoSync failed for %s, error %s", ldap.Id, err))
|
logs.Warning(fmt.Sprintf("autoSync failed for %s, error %s", ldap.Id, err))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -111,6 +112,8 @@ func (l *LdapAutoSynchronizer) syncRoutine(ldap *Ldap, stopChan chan struct{}) e
|
|||||||
} else {
|
} else {
|
||||||
logs.Info(fmt.Sprintf("ldap autosync success, %d new users, %d existing users", len(users)-len(existed), len(existed)))
|
logs.Info(fmt.Sprintf("ldap autosync success, %d new users, %d existing users", len(users)-len(existed), len(existed)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
conn.Close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -81,6 +81,17 @@ func (ldap *Ldap) GetLdapConn() (c *LdapConn, err error) {
|
|||||||
return &LdapConn{Conn: conn, IsAD: isAD}, nil
|
return &LdapConn{Conn: conn, IsAD: isAD}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (l *LdapConn) Close() {
|
||||||
|
if l.Conn == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err := l.Conn.Unbind()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func isMicrosoftAD(Conn *goldap.Conn) (bool, error) {
|
func isMicrosoftAD(Conn *goldap.Conn) (bool, error) {
|
||||||
SearchFilter := "(objectClass=*)"
|
SearchFilter := "(objectClass=*)"
|
||||||
SearchAttributes := []string{"vendorname", "vendorversion", "isGlobalCatalogReady", "forestFunctionality"}
|
SearchAttributes := []string{"vendorname", "vendorversion", "isGlobalCatalogReady", "forestFunctionality"}
|
||||||
|
@@ -120,7 +120,11 @@ func checkPermissionValid(permission *Permission) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
groupingPolicies := getGroupingPolicies(permission)
|
groupingPolicies, err := getGroupingPolicies(permission)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if len(groupingPolicies) > 0 {
|
if len(groupingPolicies) > 0 {
|
||||||
_, err = enforcer.AddGroupingPolicies(groupingPolicies)
|
_, err = enforcer.AddGroupingPolicies(groupingPolicies)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -23,6 +23,7 @@ import (
|
|||||||
"github.com/casbin/casbin/v2/log"
|
"github.com/casbin/casbin/v2/log"
|
||||||
"github.com/casbin/casbin/v2/model"
|
"github.com/casbin/casbin/v2/model"
|
||||||
"github.com/casdoor/casdoor/conf"
|
"github.com/casdoor/casdoor/conf"
|
||||||
|
"github.com/casdoor/casdoor/util"
|
||||||
xormadapter "github.com/casdoor/xorm-adapter/v3"
|
xormadapter "github.com/casdoor/xorm-adapter/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -137,6 +138,16 @@ func getPolicies(permission *Permission) [][]string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getRolesInRole(roleId string, visited map[string]struct{}) ([]*Role, error) {
|
func getRolesInRole(roleId string, visited map[string]struct{}) ([]*Role, error) {
|
||||||
|
roleOwner, roleName := util.GetOwnerAndNameFromId(roleId)
|
||||||
|
if roleName == "*" {
|
||||||
|
roles, err := GetRoles(roleOwner)
|
||||||
|
if err != nil {
|
||||||
|
return []*Role{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return roles, nil
|
||||||
|
}
|
||||||
|
|
||||||
role, err := GetRole(roleId)
|
role, err := GetRole(roleId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []*Role{}, err
|
return []*Role{}, err
|
||||||
@@ -162,7 +173,7 @@ func getRolesInRole(roleId string, visited map[string]struct{}) ([]*Role, error)
|
|||||||
return roles, nil
|
return roles, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getGroupingPolicies(permission *Permission) [][]string {
|
func getGroupingPolicies(permission *Permission) ([][]string, error) {
|
||||||
var groupingPolicies [][]string
|
var groupingPolicies [][]string
|
||||||
|
|
||||||
domainExist := len(permission.Domains) > 0
|
domainExist := len(permission.Domains) > 0
|
||||||
@@ -170,12 +181,18 @@ func getGroupingPolicies(permission *Permission) [][]string {
|
|||||||
|
|
||||||
for _, roleId := range permission.Roles {
|
for _, roleId := range permission.Roles {
|
||||||
visited := map[string]struct{}{}
|
visited := map[string]struct{}{}
|
||||||
|
|
||||||
|
if roleId == "*" {
|
||||||
|
roleId = util.GetId(permission.Owner, "*")
|
||||||
|
}
|
||||||
|
|
||||||
rolesInRole, err := getRolesInRole(roleId, visited)
|
rolesInRole, err := getRolesInRole(roleId, visited)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, role := range rolesInRole {
|
for _, role := range rolesInRole {
|
||||||
roleId := role.GetId()
|
roleId = role.GetId()
|
||||||
for _, subUser := range role.Users {
|
for _, subUser := range role.Users {
|
||||||
if domainExist {
|
if domainExist {
|
||||||
for _, domain := range permission.Domains {
|
for _, domain := range permission.Domains {
|
||||||
@@ -198,7 +215,7 @@ func getGroupingPolicies(permission *Permission) [][]string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return groupingPolicies
|
return groupingPolicies, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func addPolicies(permission *Permission) error {
|
func addPolicies(permission *Permission) error {
|
||||||
@@ -231,7 +248,10 @@ func addGroupingPolicies(permission *Permission) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
groupingPolicies := getGroupingPolicies(permission)
|
groupingPolicies, err := getGroupingPolicies(permission)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if len(groupingPolicies) > 0 {
|
if len(groupingPolicies) > 0 {
|
||||||
_, err = enforcer.AddGroupingPolicies(groupingPolicies)
|
_, err = enforcer.AddGroupingPolicies(groupingPolicies)
|
||||||
@@ -249,7 +269,10 @@ func removeGroupingPolicies(permission *Permission) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
groupingPolicies := getGroupingPolicies(permission)
|
groupingPolicies, err := getGroupingPolicies(permission)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if len(groupingPolicies) > 0 {
|
if len(groupingPolicies) > 0 {
|
||||||
_, err = enforcer.RemoveGroupingPolicies(groupingPolicies)
|
_, err = enforcer.RemoveGroupingPolicies(groupingPolicies)
|
||||||
@@ -287,7 +310,12 @@ func getAllValues(userId string, fn func(enforcer *casbin.Enforcer) []string) ([
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, role := range GetAllRoles(userId) {
|
allRoles, err := GetAllRoles(userId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, role := range allRoles {
|
||||||
permissionsByRole, err := GetPermissionsByRole(role)
|
permissionsByRole, err := GetPermissionsByRole(role)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -321,17 +349,17 @@ func GetAllActions(userId string) ([]string, error) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAllRoles(userId string) []string {
|
func GetAllRoles(userId string) ([]string, error) {
|
||||||
roles, err := getRolesByUser(userId)
|
roles, err := getRolesByUser(userId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var res []string
|
res := []string{}
|
||||||
for _, role := range roles {
|
for _, role := range roles {
|
||||||
res = append(res, role.Name)
|
res = append(res, role.Name)
|
||||||
}
|
}
|
||||||
return res
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetBuiltInModel(modelText string) (model.Model, error) {
|
func GetBuiltInModel(modelText string) (model.Model, error) {
|
||||||
|
@@ -144,6 +144,48 @@ func getTokenByCode(code string) (*Token, error) {
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetTokenByAccessToken(accessToken string) (*Token, error) {
|
||||||
|
token := Token{AccessTokenHash: getTokenHash(accessToken)}
|
||||||
|
existed, err := ormer.Engine.Get(&token)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !existed {
|
||||||
|
token = Token{AccessToken: accessToken}
|
||||||
|
existed, err = ormer.Engine.Get(&token)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !existed {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
return &token, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetTokenByRefreshToken(refreshToken string) (*Token, error) {
|
||||||
|
token := Token{RefreshTokenHash: getTokenHash(refreshToken)}
|
||||||
|
existed, err := ormer.Engine.Get(&token)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !existed {
|
||||||
|
token = Token{RefreshToken: refreshToken}
|
||||||
|
existed, err = ormer.Engine.Get(&token)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !existed {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
return &token, nil
|
||||||
|
}
|
||||||
|
|
||||||
func updateUsedByCode(token *Token) bool {
|
func updateUsedByCode(token *Token) bool {
|
||||||
affected, err := ormer.Engine.Where("code=?", token.Code).Cols("code_is_used").Update(token)
|
affected, err := ormer.Engine.Where("code=?", token.Code).Cols("code_is_used").Update(token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -219,18 +261,16 @@ func DeleteToken(token *Token) (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ExpireTokenByAccessToken(accessToken string) (bool, *Application, *Token, error) {
|
func ExpireTokenByAccessToken(accessToken string) (bool, *Application, *Token, error) {
|
||||||
token := Token{AccessTokenHash: getTokenHash(accessToken)}
|
token, err := GetTokenByAccessToken(accessToken)
|
||||||
existed, err := ormer.Engine.Get(&token)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, nil, nil, err
|
return false, nil, nil, err
|
||||||
}
|
}
|
||||||
|
if token == nil {
|
||||||
if !existed {
|
|
||||||
return false, nil, nil, nil
|
return false, nil, nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
token.ExpiresIn = 0
|
token.ExpiresIn = 0
|
||||||
affected, err := ormer.Engine.ID(core.PK{token.Owner, token.Name}).Cols("expires_in").Update(&token)
|
affected, err := ormer.Engine.ID(core.PK{token.Owner, token.Name}).Cols("expires_in").Update(token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, nil, nil, err
|
return false, nil, nil, err
|
||||||
}
|
}
|
||||||
@@ -240,22 +280,7 @@ func ExpireTokenByAccessToken(accessToken string) (bool, *Application, *Token, e
|
|||||||
return false, nil, nil, err
|
return false, nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return affected != 0, application, &token, nil
|
return affected != 0, application, token, nil
|
||||||
}
|
|
||||||
|
|
||||||
func GetTokenByAccessToken(accessToken string) (*Token, error) {
|
|
||||||
// Check if the accessToken is in the database
|
|
||||||
token := Token{AccessTokenHash: getTokenHash(accessToken)}
|
|
||||||
existed, err := ormer.Engine.Get(&token)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if !existed {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return &token, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetTokenByTokenAndApplication(token string, application string) (*Token, error) {
|
func GetTokenByTokenAndApplication(token string, application string) (*Token, error) {
|
||||||
@@ -457,16 +482,17 @@ func RefreshToken(grantType string, refreshToken string, scope string, clientId
|
|||||||
ErrorDescription: "client_id is invalid",
|
ErrorDescription: "client_id is invalid",
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if clientSecret != "" && application.ClientSecret != clientSecret {
|
if clientSecret != "" && application.ClientSecret != clientSecret {
|
||||||
return &TokenError{
|
return &TokenError{
|
||||||
Error: InvalidClient,
|
Error: InvalidClient,
|
||||||
ErrorDescription: "client_secret is invalid",
|
ErrorDescription: "client_secret is invalid",
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// check whether the refresh token is valid, and has not expired.
|
// check whether the refresh token is valid, and has not expired.
|
||||||
token := Token{RefreshTokenHash: getTokenHash(refreshToken)}
|
token, err := GetTokenByRefreshToken(refreshToken)
|
||||||
existed, err := ormer.Engine.Get(&token)
|
if err != nil || token == nil {
|
||||||
if err != nil || !existed {
|
|
||||||
return &TokenError{
|
return &TokenError{
|
||||||
Error: InvalidGrant,
|
Error: InvalidGrant,
|
||||||
ErrorDescription: "refresh token is invalid, expired or revoked",
|
ErrorDescription: "refresh token is invalid, expired or revoked",
|
||||||
@@ -477,6 +503,12 @@ func RefreshToken(grantType string, refreshToken string, scope string, clientId
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if cert == nil {
|
||||||
|
return &TokenError{
|
||||||
|
Error: InvalidGrant,
|
||||||
|
ErrorDescription: fmt.Sprintf("cert: %s cannot be found", application.Cert),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
_, err = ParseJwtToken(refreshToken, cert)
|
_, err = ParseJwtToken(refreshToken, cert)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -485,6 +517,7 @@ func RefreshToken(grantType string, refreshToken string, scope string, clientId
|
|||||||
ErrorDescription: fmt.Sprintf("parse refresh token error: %s", err.Error()),
|
ErrorDescription: fmt.Sprintf("parse refresh token error: %s", err.Error()),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// generate a new token
|
// generate a new token
|
||||||
user, err := getUser(application.Organization, token.User)
|
user, err := getUser(application.Organization, token.User)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -502,6 +535,7 @@ func RefreshToken(grantType string, refreshToken string, scope string, clientId
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
newAccessToken, newRefreshToken, tokenName, err := generateJwtToken(application, user, "", scope, host)
|
newAccessToken, newRefreshToken, tokenName, err := generateJwtToken(application, user, "", scope, host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &TokenError{
|
return &TokenError{
|
||||||
@@ -529,7 +563,7 @@ func RefreshToken(grantType string, refreshToken string, scope string, clientId
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = DeleteToken(&token)
|
_, err = DeleteToken(token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -542,7 +576,6 @@ func RefreshToken(grantType string, refreshToken string, scope string, clientId
|
|||||||
ExpiresIn: newToken.ExpiresIn,
|
ExpiresIn: newToken.ExpiresIn,
|
||||||
Scope: newToken.Scope,
|
Scope: newToken.Scope,
|
||||||
}
|
}
|
||||||
|
|
||||||
return tokenWrapper, nil
|
return tokenWrapper, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -754,13 +787,13 @@ func GetClientCredentialsToken(application *Application, clientSecret string, sc
|
|||||||
|
|
||||||
// GetTokenByUser
|
// GetTokenByUser
|
||||||
// Implicit flow
|
// Implicit flow
|
||||||
func GetTokenByUser(application *Application, user *User, scope string, host string) (*Token, error) {
|
func GetTokenByUser(application *Application, user *User, scope string, nonce string, host string) (*Token, error) {
|
||||||
err := ExtendUserWithRolesAndPermissions(user)
|
err := ExtendUserWithRolesAndPermissions(user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
accessToken, refreshToken, tokenName, err := generateJwtToken(application, user, "", scope, host)
|
accessToken, refreshToken, tokenName, err := generateJwtToken(application, user, nonce, scope, host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@@ -132,6 +132,9 @@ func (pp *StripePaymentProvider) Notify(body []byte, orderId string) (*NotifyRes
|
|||||||
}
|
}
|
||||||
// Once payment is successful, the Checkout Session will contain a reference to the successful `PaymentIntent`
|
// Once payment is successful, the Checkout Session will contain a reference to the successful `PaymentIntent`
|
||||||
sIntent, err := stripeIntent.Get(sCheckout.PaymentIntent.ID, nil)
|
sIntent, err := stripeIntent.Get(sCheckout.PaymentIntent.ID, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
var (
|
var (
|
||||||
productName string
|
productName string
|
||||||
productDisplayName string
|
productDisplayName string
|
||||||
|
@@ -303,7 +303,7 @@ class PermissionEditPage extends React.Component {
|
|||||||
{Setting.getLabel(i18next.t("role:Sub roles"), i18next.t("role:Sub roles - Tooltip"))} :
|
{Setting.getLabel(i18next.t("role:Sub roles"), i18next.t("role:Sub roles - Tooltip"))} :
|
||||||
</Col>
|
</Col>
|
||||||
<Col span={22} >
|
<Col span={22} >
|
||||||
<Select disabled={!this.hasRoleDefinition(this.state.model)} virtual={false} mode="multiple" style={{width: "100%"}} value={this.state.permission.roles}
|
<Select disabled={!this.hasRoleDefinition(this.state.model)} placeholder={this.hasRoleDefinition(this.state.model) ? "" : "This field is disabled because the model is empty or it doesn't support RBAC (in another word, doesn't contain [role_definition])"} virtual={false} mode="multiple" style={{width: "100%"}} value={this.state.permission.roles}
|
||||||
onChange={(value => {this.updatePermissionField("roles", value);})}
|
onChange={(value => {this.updatePermissionField("roles", value);})}
|
||||||
options={[
|
options={[
|
||||||
Setting.getOption(i18next.t("organization:All"), "*"),
|
Setting.getOption(i18next.t("organization:All"), "*"),
|
||||||
@@ -323,7 +323,7 @@ class PermissionEditPage extends React.Component {
|
|||||||
})}
|
})}
|
||||||
options={[
|
options={[
|
||||||
Setting.getOption(i18next.t("organization:All"), "*"),
|
Setting.getOption(i18next.t("organization:All"), "*"),
|
||||||
...this.state.permission.domains.map((domain) => Setting.getOption(domain, domain)),
|
...this.state.permission.domains.filter(domain => domain !== "*").map((domain) => Setting.getOption(domain, domain)),
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
</Col>
|
</Col>
|
||||||
|
Reference in New Issue
Block a user