IDP Token获取问题

您好,我使用的cuba7.2.2版本.
按您的step1使用idp获取ticket,能获取到ticket.
image
但是step2中,sp获取token,却出错了.(此处sp与idp服务是分开的,且各自有各自的数据库)
image

idp配置:

cuba.webAppUrl = http://cuba1:8080/app/
cuba.idp.serviceProviderUrls = http://cuba1:8080/app,http://cuba2:8081/app2,http://cuba3:8082/app3
cuba.idp.serviceProviderUrlMasks = http://cuba1:8080/app/.*,http://cuba2:8081/app2/.*,http://cuba3:8082/app3/.*
cuba.idp.serviceProviderLogoutUrls = http://cuba1:8080/app/dispatch/idpc/logout,http://cuba2:8081/app2/dispatch/idpc/logout,http://cuba3:8082/app3/dispatch/idpc/logout
cuba.idp.trustedServicePassword = 123456
cuba.web.idp.baseUrl = http://cuba1:8080/app/idp/
cuba.web.idp.trustedServicePassword = 123456
cuba.web.idp.enabled =true

sp配置:

cuba.rest.client.id=admin
cuba.rest.client.secret=123456
cuba.rest.idp.baseUrl = ${cuba.web.idp.baseUrl}
cuba.rest.idp.enabled = true
cuba.rest.idp.trustedServicePassword = ${cuba.web.idp.trustedServicePassword}
cuba.rest.idp.defaultRedirectUrl = https://www.baidu.com
cuba.idp.trustedServicePassword = ${cuba.web.idp.trustedServicePassword}
cuba.web.idp.enabled =true
cuba.web.idp.baseUrl = http://cuba1:8080/app/idp/
#cuba.web.idp.baseUrl = http://198.18.19.202:28080/app/idp/
cuba.web.idp.trustedServicePassword = 123456

期待您的回复.

image

Auth这块按我图上的配一下。

这里的用户名密码和获取普通token时用的一样,参见文档:https://doc.cuba-platform.com/restapi-7.2/
image

Body配置看上去是对的。
image

按您的配置加上authorization之后.
image
后台日志
image

我获取ticket是用的admin用户,
按理说不会没权限吧?

另外,我新建一个项目,没加idp,直接使用oauth2,也是这个错误
image
最开始怀疑是admin用户禁止被使用到rest接口,后来新建用户赋予rest权限,但结果一样.

cuba在7.2对restApi加了新的限制。
image

但是我目前手头没有7.2的项目。

你看下文档 5. Security Implications When Using REST API 先。

刚才试了下普通的restApi,需要额外创建一个角色赋给用户,然后就可以了
image

感谢您的回复,问题解决了. :blush:
image

但是有些值得注意的地方:

  1. 在idp中获取ticket的用户,在sp服务中也必须存在,否则获取token时会出现unauthorized.比如我就在两个服务中都创建了rest用户才成功.
  2. 调用sp的rest接口时,权限树是跟sp服务的用户一样的,不是idp服务的用户,这也就解释了为什么idp的用户必须存在于sp服务中.否则两个服务库对不上,权限树不一样,就有bug了.

最后,我想问一下,通过idp获取ticket后,再去sp中拿token是否是唯一的rest+idp解决方式? :thinking:

是官方的方式吧。注意idpTicket只能用一次,用完就失效了。

至于idp+rest的方式,肯定有各种方式,熟悉了机制以后,可以考虑怎么调整下更适合自己的项目 :slight_smile: