我已经将keycloak与角度应用程序集成在一起.基本上,前端和后端都在不同的服务器上.Backend应用程序在apache tomcat 8上运行.前端应用程序正在JBoss欢迎内容文件夹上运行.
Angular配置
angular.element(document).ready(function ($http) {
var keycloakAuth = new Keycloak('keycloak.json');
auth.loggedIn = false;
keycloakAuth.init({ onLoad: 'login-required' }).success(function () {
keycloakAuth.loadUserInfo().success(function (userInfo) {
console.log(userInfo);
});
auth.loggedIn = true;
auth.authz = keycloakAuth;
auth.logoutUrl = keycloakAuth.authServerUrl + "/realms/app1/protocol/openid-connect/logout?redirect_uri=http://35.154.214.8/hrms-keycloak/index.html";
module.factory('Auth', function() {
return auth;
});
angular.bootstrap(document, ["themesApp"]);
}).error(function () {
window.location.reload();
});
});
module.factory('authInterceptor', function($q, Auth) {
return {
request: function (config) {
var deferred = $q.defer();
if (Auth.authz.token) {
Auth.authz.updateToken(5).success(function() {
config.headers = config.headers || {};
config.headers.Authorization = 'Bearer ' + …
Run Code Online (Sandbox Code Playgroud) 设置aud
声明以避免下面的错误的正确方法是什么?
unable to verify the id token {"error": "oidc: JWT claims invalid: invalid claims, 'aud' claim and 'client_id' do not match, aud=account, client_id=webapp"}
Run Code Online (Sandbox Code Playgroud)
我有点解决这个错误信息,硬编码aud
声称与我的相同client_id
.有没有更好的方法?
这是我的docker-compose.yml
:
version: '3'
services:
keycloak-proxy:
image: "keycloak/keycloak-gatekeeper"
environment:
- PROXY_LISTEN=0.0.0.0:3000
- PROXY_DISCOVERY_URL=http://keycloak.example.com:8181/auth/realms/realmcom
- PROXY_CLIENT_ID=webapp
- PROXY_CLIENT_SECRET=0b57186c-e939-48ff-aa17-cfd3e361f65e
- PROXY_UPSTREAM_URL=http://test-server:8000
ports:
- "8282:3000"
command:
- "--verbose"
- "--enable-refresh-tokens=true"
- "--enable-default-deny=true"
- "--resources=uri=/*"
- "--enable-session-cookies=true"
- "--encryption-key=AgXa7xRcoClDEU0ZDSH4X0XhL5Qy2Z2j"
test-server:
image: "test-server"
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用我正在构建的 Android 应用程序对 keycloak 服务器进行 OIDC 身份验证/授权。
我收到以下错误,这导致我在我的应用程序中收到 502:
2019/08/15 00:29:04 [error] 31921#31921: *64410338 upstream sent too big header while reading response header from upstream, client: 192.168.4.61, server: stage.example.com, request: "GET /auth/realms/master/protocol/openid-connect/auth?client_id=example-mobile-android&redirect_uri=http%3A%2F%2Flocalhost%3A53978%2F%23%2Flogin&state=a627edff-c1a2-43d3-8c6e-e5635bcc2252&response_mode=fragment&response_type=id_token%20token&scope=openid&nonce=69967773-36ba-49b2-8dd8-a31fd36f412b&prompt=none HTTP/1.1", upstream: "http://192.168.4.147:8080/auth/realms/master/protocol/openid-connect/auth?client_id=example-mobile-android&redirect_uri=http%3A%2F%2Flocalhost%3A53978%2F%23%2Flogin&state=a627edff-c1a2-43d3-8c6e-e5635bcc2252&response_mode=fragment&response_type=id_token%20token&scope=openid&nonce=69967773-36ba-49b2-8dd8-a31fd36f412b&prompt=none", host: "www.example.com", referrer: "http://localhost:53978/"
Run Code Online (Sandbox Code Playgroud)
我已经尝试过这两种方法:
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
Run Code Online (Sandbox Code Playgroud)
以及完全禁用代理缓冲区。
可能发生什么事?我要进一步扩大缓冲区吗?还有其他我没有发现的错误吗?
有一个在本地运行的网络服务器,我想在 iframe 内有 Keycloak(在另一个域上)登录页面。我在 Keycloak Real Settings > Security Defenses > Headers > Content-Security-Policy 中尝试了以下设置
frame-src 'self' http://127.0.0.1 http://192.168.1.140 http://localhost *.home-life.hub http://trex-macbook.home-life.hub localhost; frame-ancestors 'self'; object-src 'none';
Run Code Online (Sandbox Code Playgroud)
基本上,我将本地 IP 地址和主机名作为frame-src
.
登录页面未显示,我在浏览器控制台中收到此错误
Refused to display 'http://keycloak.example.com:8080/auth/realms/master/protocol/openid-connect/auth?client_id=es-openid&response_type=code&redirect_uri=https%3A%2F%2Fkibana.example.com%3A5601%2Fauth%2Fopenid%2Flogin&state=3RV-_nbW-RvmB8EfUwgkJq&scope=profile%20email%20openid' in a frame because an ancestor violates the following Content Security Policy directive: "frame-ancestors 'self'".
Run Code Online (Sandbox Code Playgroud)
我的服务器和 UI(服务器呈现)代码:
'use strict';
const Hapi = require('@hapi/hapi');
const init = async () => {
// Run server on all interfaces
const server = Hapi.server({
port: 3000, …
Run Code Online (Sandbox Code Playgroud) 我已经在 EKS 集群上部署了 keycloak,并且能够成功访问仪表板并已经创建了一个新领域。
于是我想到测试我的keycloak,就去https://www.keycloak.org/app/进行测试。
我创建了一个根 URL 为“https://www.keycloak.org/app/”的客户端,并创建了一个用户。我已经使用我的领域的帐户登录成功测试了我的用户。
然后我去https://www.keycloak.org/app/输入我的 keycloak URL 作为https://keycloak.test.nip.io,领域作为 Test(与我的领域同名),然后客户端名称作为一个门户(在 keycloak 上创建的同名客户端)。
当我点击“登录”时,它会重定向到我的 keycloak URL,但显示“我们很抱歉...找不到页面”
任何人都知道我为什么会收到此错误以及如何避免该错误。
keycloak keycloak-services keycloak-gatekeeper keycloak-connect keycloak-rest-api
我有一个用例,当用户连续 5 次输入错误密码时应被禁用。我找不到任何 keycloak 密码策略来在用户连续 5 次输入错误密码时禁用用户。
我正在尝试将 keycloak 与 React 应用程序一起使用,这是我当前的客户端配置...我在主领域内执行此操作
这是我的钥匙斗篷配置
export const keycloakConfig = {
"realm": "master",
"auth-server-url": "http://localhost:8180/",
"ssl-required": "external",
"resource": "demo",
"public-client": true,
"confidential-port": 0,
"clientId" : "demo",
"url" : "http://localhost:8180/"
};
Run Code Online (Sandbox Code Playgroud)
我的代码基于 此存储库
现在...我可以在我的应用程序中毫无问题地登录,显示的网址是这样的
http://localhost:8180/realms/master/protocol/openid-connect/auth?client_id=demo&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2F&state=ba9daf04-ffdb-4ad3-b912-8be846f0684b&response_mode=fragment&response_type=code&scope=openid&nonce=558d71b7-2c66-44f8-9297-84694dc571a8
Run Code Online (Sandbox Code Playgroud)
但是当我尝试注销时收到一条消息
Invalid parameter: redirect_uri
Run Code Online (Sandbox Code Playgroud)
注销网址是这样的
http://localhost:8180/realms/master/protocol/openid-connect/logout?redirect_uri=http%3A%2F%2Flocalhost%3A3000%2F
Run Code Online (Sandbox Code Playgroud)
我不确定我的客户端配置是否正确,因为我发现的几乎所有教程中都缺少几个参数
你知道这里可能有什么问题吗?感谢你们
我有一个在 EKS 集群中运行的 Keycloak 服务器,我尝试将其配置为生产模式而不是开发模式。
我已经设法让 SSL 与反向代理一起使用,但是当我进入管理控制台的登录页面时,它只是无限期地加载。
这是我的配置:
Dockerfile
FROM --platform=linux/arm64 quay.io/keycloak/keycloak:19.0.1 as builder
ENV KC_DB=postgres
ENV KC_PROXY=edge
ENV KC_HEALTH_ENABLED=true
ENV KC_METRICS_ENABLED=true
ENV KC_FEATURES=token-exchange
ENV KC_HTTP_RELATIVE_PATH=/auth
RUN /opt/keycloak/bin/kc.sh build
FROM --platform=linux/arm64 quay.io/keycloak/keycloak:19.0.1
COPY --from=builder /opt/keycloak/ /opt/keycloak/
## Install custom providers
COPY auth-identione-extension/target/auth-identione-extension-1.0.0-SNAPSHOT.jar /opt/keycloak/providers
ENV KC_HOSTNAME_STRICT=false
ENV KC_KEYCLOAK_USER={user}
ENV KC_KEYCLOAK_PASSWORD={password}
ENV KC_DB_URL={dburl}
ENV KC_DB_USERNAME={dbusername}
ENV KC_DB_PASSWORD={dbpassword}
ENV KC_HTTP_ENABLED=true
ENV KC_HOSTNAME=auth.identione.com
ENTRYPOINT ["/opt/keycloak/bin/kc.sh", "start", "--optimized"]
Run Code Online (Sandbox Code Playgroud)
部署.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: default
name: keycloak-deployment
spec:
selector:
matchLabels:
app.kubernetes.io/name: keycloak-app
replicas: …
Run Code Online (Sandbox Code Playgroud) 我正在使用keycloak来确保我的休息服务.我正在参考这里给出的教程.我创造了休息和前端.现在当我在后端添加keycloak时,当我的前端进行api调用时,我收到CORS错误.
Spring启动时的Application.java文件看起来像
@SpringBootApplication
public class Application
{
public static void main( String[] args )
{
SpringApplication.run(Application.class, args);
}
@Bean
public WebMvcConfigurer corsConfiguration() {
return new WebMvcConfigurerAdapter() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/api/*")
.allowedMethods(HttpMethod.GET.toString(), HttpMethod.POST.toString(),
HttpMethod.PUT.toString(), HttpMethod.DELETE.toString(), HttpMethod.OPTIONS.toString())
.allowedOrigins("*");
}
};
}
}
Run Code Online (Sandbox Code Playgroud)
application.properties文件中的keycloak属性如下所示
keycloak.realm = demo
keycloak.auth-server-url = http://localhost:8080/auth
keycloak.ssl-required = external
keycloak.resource = tutorial-backend
keycloak.bearer-only = true
keycloak.credentials.secret = 123123-1231231-123123-1231
keycloak.cors = true
keycloak.securityConstraints[0].securityCollections[0].name = spring secured api
keycloak.securityConstraints[0].securityCollections[0].authRoles[0] = admin
keycloak.securityConstraints[0].securityCollections[0].authRoles[1] = user
keycloak.securityConstraints[0].securityCollections[0].patterns[0] …
Run Code Online (Sandbox Code Playgroud) 我正在尝试做一件简单的事情。
想要向单个端点发出请求并发送承载令牌(来自客户端),我希望验证该令牌,并取决于端点上keycloak接受/拒绝请求上分配的角色。
我遵循了许多教程甚至书籍,但是其中大多数我根本不理解。
遵循此设置我的密钥斗篷信息(领域,角色,用户) https://medium.com/@bcarunmail/securing-rest-api-using-keycloak-and-spring-oauth2-6ddf3a1efcc2
所以,
我基本上是通过客户端,具有特定角色“用户”的用户来设置我的密钥斗篷,并像这样进行配置:
@Configuration
@KeycloakConfiguration
//@ComponentScan(basePackageClasses = KeycloakSecurityComponents.class)
public class SecurityConf extends KeycloakWebSecurityConfigurerAdapter
{
/**
* Registers the KeycloakAuthenticationProvider with the authentication manager.
*/
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(keycloakAuthenticationProvider());
}
/**
* Defines the session authentication strategy.
*/
@Bean
@Override
protected SessionAuthenticationStrategy sessionAuthenticationStrategy() {
return new RegisterSessionAuthenticationStrategy(new SessionRegistryImpl());
}
@Bean
public KeycloakSpringBootConfigResolver KeycloakConfigResolver() {
return new KeycloakSpringBootConfigResolver();
}
@Bean
public FilterRegistrationBean keycloakAuthenticationProcessingFilterRegistrationBean(
KeycloakAuthenticationProcessingFilter filter) {
FilterRegistrationBean registrationBean = new FilterRegistrationBean(filter);
registrationBean.setEnabled(false);
return …
Run Code Online (Sandbox Code Playgroud)