我正在使用 Keycloak 来验证我的 Spring Boot 应用程序,
我已经与客户端(聊天系统)创建了一个新领域(CommonServices)
我有这个配置
keycloak:
auth-server-url: http://localhost:8083/auth
realm: CommonServices
resource: chatting-system
public-client: true
principal-attribute: preferred_username
use-resource-role-mappings: true
security-constraints[0].authRoles[0]: user
ssl-required: external
spring:
data:
mongodb:
host: localhost
port: 27017
database: Chat
username: saga
password: password
security:
oauth2:
resourceserver:
jwt:
jwk-set-uri: http://localhost:8083/auth/realms/CommonServices/protocol/openid-connect/certs
issuer-uri: http://localhost:8083/auth/realms/CommonServices
Run Code Online (Sandbox Code Playgroud)
我已经配置了安全性:
@KeycloakConfiguration
class SecurityConfig extends KeycloakWebSecurityConfigurerAdapter {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
KeycloakAuthenticationProvider keycloakAuthenticationProvider = keycloakAuthenticationProvider();
auth.authenticationProvider(keycloakAuthenticationProvider);
}
@Bean
@Override
protected SessionAuthenticationStrategy sessionAuthenticationStrategy() {
return new RegisterSessionAuthenticationStrategy(new SessionRegistryImpl());
}
@Override
protected …Run Code Online (Sandbox Code Playgroud) 我在 iframe 中使用 keycloak。在我的钥匙斗篷后面是一些二级 IDP,例如 google 和 facebook。
根据我当前的配置,keycloak 只是重定向到那些辅助 IDP。这意味着它们也在 iframe 中打开。我真的很想改变这一点,因为它与我的一些主要安全政策相矛盾。
我可以以某种方式告诉 keycloak 在弹出窗口中打开外部 IDP 吗?我已阅读 keycloak“服务器管理指南”,但找不到任何有关此问题的信息。
我们正在使用keycloak 的 helm 图表,
我可以配置日志的内部视图(在网络界面中)。是否可以将这些日志也发送到logstash?
例如,我想admin使用admin-cli客户端创建一个新客户端。
令牌生成工作正常:
POST /auth/realms/master/protocol/openid-connect/token
b'username=admin&password=admin&grant_type=password&client_id=admin-cli'
Run Code Online (Sandbox Code Playgroud)
使用该令牌我还可以执行一些查询,例如当我需要获取客户端的 ID 时:
GET /auth/admin/realms/master/clients?clientId=my-test-cli
H' Authorization: Bearer xyz
H' Content-Type: application/json
Run Code Online (Sandbox Code Playgroud)
但是,当我想创建新的客户端角色或新客户端时,我总是会收到400错误。我将 Keycloak 服务器中的日志级别更改为DEBUG,但除了看到表明令牌已成功创建的日志之外,没有任何用处。
POST /auth/admin/realms/master/clients/7534ac42-fe8b-4cde-b6c6-c385f4958e3b/roles
400 {"error":"unknown_error"}
Run Code Online (Sandbox Code Playgroud)
我正在使用与 JBoss Wildfly 容器一起运行的 Python v3.x 和 Keycloak v14.0.0。
看看admin用户,它似乎拥有所有角色,如admin、default-roles-master,create-realm并且我在列表中没有看到任何要分配的角色,因为它似乎拥有一切。对于客户来说也是如此admin-cli。这两个配置(admin user 和 admin-cli)是您第一次启动服务器时的默认配置。我是否需要任何额外的东西,例如创建新角色或其他东西才能使其正常工作?
我创建机密客户端的有效负载:
payload = {
"name": "Some Name",
"clientId": "some-name",
"secret": "some-name-secret",
"enabled": true,
"publicClient": false,
"authorizationServicesEnabled": true,
"redirectUris" : ["/*"]
}
Run Code Online (Sandbox Code Playgroud) 我有 keycloak spring 微服务和使用 keycloak 适配器和 keycloak-spring-boot-starter 的常规 java spring 服务。当 keycloak 发出有效令牌并且我将其传递给 spring 服务时,验证令牌是有效的并且一切正常。
如果我重新启动 keycloak 服务并将之前颁发的令牌再次传递给 spring 服务,验证将再次通过。这是为什么?我希望 spring 能够弄清楚该令牌是由先前存在的 keycloak 实例颁发的,并报告无效令牌。
我有一个 Keycloak 领域,其中一些用户作为 Nodejs + Typescript 项目的 IdP。
如果我按“全部注销”,它们就会从这里消失,但它们仍然有效。
例子:
1) I create a new session. I get its JWT token as a response
2) I do a GET req on one of the protected routes with the token attached. It works.
4) I logout all sessions by pressing the button in that photo
5) I do the same GET req on the same protected route. It still works.
I expect it NOT to work, because I previously logged …Run Code Online (Sandbox Code Playgroud) 我对keycloak有问题。所以,我有带有 keycloak 的 spring-microservices。如果它从本地开始,那么干得好。但是如果我在 docker 中启动 spring 和 keycloak,那么我就会遇到安全问题。我收到401 错误:(Bearer Realm =“bingo”,error =“invalid_token”,error_description =“无效的令牌发行者。预期为'http://keycloak:8080/realms/bingo',但为'http://localhost: 8090/领域/宾果'")。我不明白,如何向 localhost keycloak:8080发送请求。请帮帮我。
spring-app 中的 Application.properties:
keycloak.auth-server-url=http://keycloak:8080
keycloak.realm=bingo
keycloak.resource=user
keycloak.ssl-required=external
keycloak.public-client=true
keycloak.bearer-only=true
keycloak.use-resource-role-mappings=true
keycloak_auth.password=FXpJokhP8ACMo9h53Hl6NSJXHSk395YG
Run Code Online (Sandbox Code Playgroud)
我的 keycloak docker-compose :
keycloak:
container_name: 'keycloak'
image: quay.io/keycloak/keycloak:18.0
environment:
DB_VENDOR: POSTGRES
DB_ADDR: kc_postgres
DB_DATABASE: keycloak
DB_USER: keycloak
DB_SCHEMA: public
DB_PASSWORD: password
KEYCLOAK_ADMIN: admin
KEYCLOAK_ADMIN_PASSWORD: admin
ports:
- '8090:8080'
depends_on:
- kc_postgres
command: start-dev
networks:
- spring
- kc_postgres
Run Code Online (Sandbox Code Playgroud)
所以,我从react-app 获取令牌。我的配置 keyclaok 文件 - keycloak.json:
{ …Run Code Online (Sandbox Code Playgroud)