如何测试 Keycloak 本机服务
该文档提供了多种服务,例如:用户管理、客户、组和会话,我尝试了多种方法来测试这些服务,但没有成功。可能是由于配置不正确
我在 Stackoverflow 上看到了一个示例,它显示了服务的正确路径
例如。 http://{地址和端口}/auth/admin/realms/{Realm}/users
还有一些关于如何在邮递员上测试的设置,但我没有成功调用
有谁有例子或者可以帮助我如何激活/使用这些服务。
谢谢!
要使用的服务:(Keycloak Admin REST API) https://www.keycloak.org/docs-api/8.0/rest-api/index.html]
问题如下。我通过 Keycloak Bearer Spring 安全性实现了登录,如下所示
public class KeycloakSecurityConfiguration extends KeycloakWebSecurityConfigurerAdapter {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
KeycloakAuthenticationProvider keycloakAuthenticationProvider = keycloakAuthenticationProvider();
keycloakAuthenticationProvider.setGrantedAuthoritiesMapper(new SimpleAuthorityMapper());
auth.authenticationProvider(keycloakAuthenticationProvider);
}
@Override
public void configure(HttpSecurity http) throws Exception {
super.configure(http);
http.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.sessionAuthenticationStrategy(sessionAuthenticationStrategy())
.and()
.csrf().disable()
.addFilterBefore(keycloakPreAuthActionsFilter(), LogoutFilter.class)
.addFilterBefore(keycloakAuthenticationProcessingFilter(), X509AuthenticationFilter.class)
.exceptionHandling().authenticationEntryPoint(authenticationEntryPoint())
.and()
.authorizeRequests().antMatchers(Constants.API_BASE_PATH + "/**").authenticated();
}
}
Run Code Online (Sandbox Code Playgroud)
@ExceptionHandler当我将授权请求标头发送为空时,keycloak 会抛出错误 401。我无法像这样捕获错误:
@ExceptionHandler(RuntimeException.class)
protected ResponseEntity<Object> keycloakAuthenticationExceptionn(RuntimeException ex) {
return buildResponseEntity(new ErrorResponseWrapper(BAD_REQUEST,new
MessageResponse(ex.getLocalizedMessage()),ex,ErrorCode.NOT_AUTHORIZED));
}
Run Code Online (Sandbox Code Playgroud) 我需要在我的 keycloak 中使用 md5 哈希算法。我知道keycloak不支持md5?是否有可能使用 md5 算法扩展哈希 keycloak 算法列表?
更新:我知道不推荐使用 md5,但由于安装的是非常旧的系统,我必须使用它。
假设我通过openid-connect成功登录后收到了令牌
http://xxxxxx/auth/realms/demo/protocol/openid-connect/token
{
"access_token": "xxxxxx",
"expires_in": 600,
"refresh_expires_in": 1800,
"refresh_token": "xxxxxx",
"token_type": "bearer",
"not-before-policy": xxxx,
"session_state": "xxxxx",
"scope": "email profile"
}
Run Code Online (Sandbox Code Playgroud)
有没有办法像https://jwt.io/那样使用 PHP解码 jwt 令牌的有效负载?谢谢。
我正在尝试设置 Keycloak,但是教程希望我访问http://localhost:8080,但我正在远程主机上设置它,并且需要从外部访问管理控制台。我尝试通过 Nginx 公开它。Keycloak 管理控制台似乎可以无缝地使用新域名和端口,但它仍然尝试使用“http”网址而不是“https”网址(我已将 Nginx 配置为将 HTTP 重定向到 HTTPS,并且我想保留出于安全原因,就这样)。我发现问题是它内部设置了一个变量:
var authServerUrl = 'http://example.com/auth';
Run Code Online (Sandbox Code Playgroud)
虽然正确的网址是https://example.com/auth.
结果,当我https://example.com/auth/admin/master/console/在浏览器中打开时,出现错误:
Refused to frame 'http://example.com/' because it violates the following Content Security Policy directive: "frame-src 'self'".
Run Code Online (Sandbox Code Playgroud)
如何解决这个问题?我使用的 Nginx 配置是:
server {
server_name example.com;
listen 80;
listen [::]:80;
location / {
return 301 https://$server_name$request_uri;
}
}
ssl_session_cache shared:ssl_session_cache:10m;
server {
server_name example.com;
listen 443 ssl http2;
listen [::]:443 ssl http2;
# ... <SSL and Gzip config goes here> ...
location …Run Code Online (Sandbox Code Playgroud) 我有一个包含黑名单密码的文本文件,并将文件名设置为“身份验证”->“密码策略”->“keycloak 中的密码黑名单”。如果有简单的密码,例如
password
admin
user
Run Code Online (Sandbox Code Playgroud)
效果很好 - 当我尝试更改密码时,我看到了这条消息Error! Invalid password: password is blacklisted.
但是当我向此列表添加更复杂的密码时,就像Music.1%它不起作用 - 我可以将密码更改为此。
为什么它会如此有效?有没有办法将文件中的类似密码列入黑名单?
在集成Keyclock SDK时,我尝试交换授权码来访问令牌
authService.performTokenRequest(
resp.createTokenExchangeRequest(),
new AuthorizationService.TokenResponseCallback() {
@Override public void onTokenRequestCompleted(
TokenResponse resp, AuthorizationException ex) {
if (resp != null) {
// exchange succeeded
} else {
// authorization failed, check ex for more details
}
}
});
Run Code Online (Sandbox Code Playgroud)
我收到以下错误,
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:354)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
at java.util.concurrent.FutureTask.run(FutureTask.java:271)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
Caused by: java.lang.IllegalArgumentException: only https connections are permitted
at net.openid.appauth.Preconditions.checkArgument(Preconditions.java:116)
at net.openid.appauth.connectivity.DefaultConnectionBuilder.openConnection(DefaultConnectionBuilder.java:51)
at net.openid.appauth.AuthorizationService$TokenRequestTask.doInBackground(AuthorizationService.java:418)
at net.openid.appauth.AuthorizationService$TokenRequestTask.doInBackground(AuthorizationService.java:395) …Run Code Online (Sandbox Code Playgroud) android android-asynctask android-backup-service keycloak appauth
我正在尝试使用 nginx 在反向代理后面设置一个 keycloak 实例,我几乎做到了。
我的(部分)docker-compose:
version: '3.4'
services:
[...]
keycloak:
image: jboss/keycloak
environment:
- DB_VENDOR=[vendor]
- DB_USER=[user]
- DB_PASSWORD=[password]
- DB_ADDR=[dbaddr]
- DB_DATABASE=[dbname]
- KEYCLOAK_USER=[adminuser]
- KEYCLOAK_PASSWORD=[adminpassword]
- KEYCLOAK_IMPORT=/tmp/my-realm.json
- KEYCLOAK_FRONTEND_URL=https://auth.mydomain.blah/auth
- PROXY_ADDRESS_FORWARDING=true
- REDIRECT_SOCKET=proxy-https
[...]
Run Code Online (Sandbox Code Playgroud)
我的 nginxconf 只是
server {
listen 443 ssl;
server_name auth.mydomain.blah;
ssl_certificate /etc/letsencrypt/live/auth.mydomain.blah/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/auth.mydomain.blah/privkey.pem;
location / {
proxy_pass http://keycloak:8080;
}
}
Run Code Online (Sandbox Code Playgroud)
它有效,我可以访问 keycloakhttps://auth.mydomain.blah/auth 但当我查看时https://auth.mydomain.blah/auth/realms/campi/.well-known/openid-configuration我得到了这个:
{
"issuer": "https://auth.mydomain.blah/auth/realms/campi",
"authorization_endpoint": "https://auth.mydomain.blah/auth/realms/campi/protocol/openid-connect/auth",
"token_endpoint": "http://keycloak:8080/auth/realms/campi/protocol/openid-connect/token",
"introspection_endpoint": "http://keycloak:8080/auth/realms/campi/protocol/openid-connect/token/introspect",
"userinfo_endpoint": "http://keycloak:8080/auth/realms/campi/protocol/openid-connect/userinfo",
"end_session_endpoint": "https://auth.mydomain.blah/auth/realms/campi/protocol/openid-connect/logout",
"jwks_uri": "http://keycloak:8080/auth/realms/campi/protocol/openid-connect/certs", …Run Code Online (Sandbox Code Playgroud) 我无法在 keyClock 的配置对象中设置客户端秘密
function initializeKeycloak(keycloak: KeycloakService) {
return () =>
keycloak.init({
config: {
url: 'http://localhost:8080/auth',
realm: 'your-realm',
clientId: 'your-client-id',
client-secret: 'xxxxxxxxxxx' <-- problem
},
initOptions: {
onLoad: 'check-sso',
silentCheckSsoRedirectUri:
window.location.origin + '/assets/silent-check-sso.html',
},
});
}
Run Code Online (Sandbox Code Playgroud)
我们可以在哪里设置客户端秘密? 请帮助我,谢谢
keycloak ×10
android ×1
appauth ×1
istio ×1
java ×1
javascript ×1
jwt ×1
kubernetes ×1
md5 ×1
nginx ×1
php ×1
spring ×1
spring-boot ×1