wpf - Keycloak - WPF 检查权限
问题描述
我有一个 WPF 应用程序(.net 462 和 API .net5.0)。
我已经在 api 上设置了 openid 并且这个工作,权限工作,但是在 WPF 应用程序上我必须检查应用程序元素的权限(菜单访问,按钮访问)。
获取令牌工作,但我不知道如何在 openid 时验证范围
关键时钟配置:
- 领域 => 演示测试
- 客户端 => 演示测试客户端
- 客户角色 => DemoRole
- 授权范围 => demo:read
- 相关权限 => 权限演示:读取
- 角色的相关政策 => DemoRole - 正面
我创建了两个用户“user-test-ok”和“user-test-ko”,“user-test-ok”具有客户端角色“DemoRole”。
我已经测试了用户的内省,以验证用户的范围为“demo:read”,但这不起作用。
我不想使用 keycloak API,我想使用 openid 系统来可能通过其他 OAuth2.0 系统更改 keycloak。
这是我尝试检查授权范围的代码:
var requestUri = new Uri($"https://localhost:8443/auth/realms/{realm}/protocol/openid-connect/token/introspect");
using (var client = new HttpClient())
{
var req = new HttpRequestMessage(HttpMethod.Post, requestUri);
req.Headers.Add("cache-control", "no-cache");
req.Headers.Add("accept", "application/x-www-form-urlencoded");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
req.Content = new FormUrlEncodedContent(new Dictionary<string, string>
{
{ "token_type_hint", "requesting_party_token" },
{ "token", tokenResult.AccessToken },
{ "client_id", clientId },
{ "client_secret", clientSecret },
{ "scope", "test:read" },
});
var response = client.SendAsync(req).Result;
if (!response.IsSuccessStatusCode)
{
throw new Exception();
}
var responseString = response.Content.ReadAsStringAsync().Result;
}
你知道怎么做吗?
解决方案
推荐阅读
- r - 使用 ggplot2 时,R 3.5.* 中不推荐使用“结构(NULL,*)”
- firebase - firebase 后端和移动/网络应用程序之间的代理(或某种)
- python - str.findall 返回值,如果找到一个元素
- database - 这是可接受的数据库设计吗?
- flutter - 如何通过 Datatable 行填充屏幕的空白空间?
- c++ - 使用 C++ 替换 std::string 中的子字符串,但不是全部替换
- angular - Use same form and functions in insert and modify components
- javascript - 无法在注册页面读取属性错误
- python - SQL 截断表,其中表名在函数参数或变量中定义
- angular - 如何检查模型在角度/打字稿中是否有效?