【问题标题】:Why authorization failed after successful authentication为什么认证成功后授权失败
【发布时间】:2020-05-26 21:20:46
【问题描述】:

我根据帖子https://apereo.github.io/2019/02/19/cas61-as-oauth-authz-server/配置了带有OAuth2.0协议(授权码授予类型)的CAS服务器

我的服务器配置(application.yml)

cas:
  server:
    name: https://casoauth.example.org:8443
    prefix: ${cas.server.name}/cas
  authn:
    accept:
      users: casuser::demo
    oauth:
      refreshToken:
        timeToKillInSeconds: 2592000
      code:
        timeToKillInSeconds: 14400
        numberOfUses: 10
      accessToken:
        timeToKillInSeconds: 14400
        maxTimeToLiveInSeconds: 28800
      grants:
        resourceOwner:
          requireServiceHeader: true
      userProfileViewType: FLAT
  ticket:
    tgt:
      maxTimeToLiveInSeconds: 28800
      timeToKillInSeconds: 14400
    st:
      timeToKillInSeconds: 14400
  serviceRegistry:
    json:
      location: classpath:/services
    initFromJson: true
logging:
  config: file:/etc/cas/config/log4j2.xml
  level:
    org:
      apereo:
        cas: DEBUG

注册应用的json

{
  "@class" : "org.apereo.cas.support.oauth.services.OAuthRegisteredService",
  "clientId": "client1",
  "clientSecret": "password1",
  "serviceId": "^https://casoauth.example.org:9999/.*",
  "name": "OAuthService",
  "id": 1000,
  "bypassApprovalPrompt": false,
  "supportedGrantTypes": [ "java.util.HashSet", [ "authorization_code" ] ],
  "supportedResponseTypes": [ "java.util.HashSet", [ "code" ] ]
}

应用配置

debug: true
server:
  port: 9999
  ssl:
    keyStore: file:/etc/cas/thekeystore
    keyStorePassword: changeit
    keyPassword: changeit

security:
  user:
    password: user
  ignored: /,/favicon.ico,/index.html,/home.html,/dashboard.html,/js/**,/css/**,/webjars/**
  sessions: ALWAYS
  oauth2:
    sso:
      loginPath: /dashboard/login
management:
  security:
    role: HERO

logging:
  level:
    org.springframework: INFO
    com.netflix.discovery: 'OFF'

---
spring:
  profiles: cas
security:
  oauth2:
    client:
      clientId: client1
      clientSecret: password1
      accessTokenUri: https://casoauth.example.org:8443/cas/oauth2.0/accessToken
      userAuthorizationUri: https://casoauth.example.org:8443/cas/oauth2.0/authorize
      clientAuthenticationScheme: form
    resource:
      userInfoUri: https://casoauth.example.org:8443/cas/oauth2.0/profile
      preferTokenInfo: false

在 CAS 服务器上进行身份验证后,我得到了

白标错误页面

此应用程序没有显式映射 /error,因此您将其视为后备。

2019 年 6 月 4 日星期二 17:10:41 CEST 出现意外错误(类型=未授权,状态=401)。 身份验证失败:无法获取访问令牌

网址https://casoauth.example.org:9999/dashboard/login?code=OC-1-lu5Hlcg2l3E4S5B68fs0-P-47tkh-4gR&state=ef17Ee

有什么想法吗?

【问题讨论】:

  • https://casoauth.example.org:8443/cas/oauth2.0/accessTokenhttps://casoauth.example.org:9999 好像不一样,端口好像不对。看看改变端口是否能解决这个问题,干杯。
  • 在 8443 上运行 CAS 服务器,在 9999 上运行客户端应用程序。我觉得这个配置没问题
  • oic,我的错误
  • 可能是jdk版本?他们特别说 SSO 需要 JDK11,应用程序需要 JDK8

标签: oauth-2.0 spring-security-oauth2 cas


【解决方案1】:

我遇到了这个问题。您应该将您的证书添加到受信任的证书中,问题就会解决。

【讨论】:

    猜你喜欢
    • 2016-07-25
    • 2021-03-23
    • 2018-10-01
    • 1970-01-01
    • 2015-06-23
    • 1970-01-01
    • 1970-01-01
    • 2017-05-11
    • 1970-01-01
    相关资源
    最近更新 更多