【发布时间】:2017-02-08 10:17:31
【问题描述】:
我无法使用 ClientAssertionCertificate 从 ADFS(Windows server 2012R2)获取 JWT。
当我让用户使用他的用户名和密码直接进入 adfs - 登录窗口进行身份验证时,一切正常,但我不希望我的应用程序显示 ADFS - 登录窗口,因为我的应用程序的用户不会'不知道凭据。我的应用程序实际上是(api)用户,所以我想使用证书进行身份验证。当我尝试这样做时,我收到消息“授权服务器不支持请求的grant_type。授权服务器仅支持authorization_code 或refresh_token 作为授权类型。
有人知道使用证书从 ADFS 获取 JWT 的任何解决方法或其他方法吗?非常感谢!
我的应用程序是一个 .Net 4.6.1 控制台应用程序。
这是我现在的代码:
var certPath = Path.Combine(GetCurrentDirectoryFromExecutingAssembly(), "mycertificate.pfx");
var certfile = File.OpenRead(certPath);
var certificateBytes = new byte[certfile.Length];
certfile.Read(certificateBytes, 0, (int)certfile.Length);
var cert = new X509Certificate2(
certificateBytes,
"mypassword",
X509KeyStorageFlags.Exportable |
X509KeyStorageFlags.MachineKeySet |
X509KeyStorageFlags.PersistKeySet);
var certificate = new ClientAssertionCertificate("myclientid", cert);
AuthenticationContext context = new AuthenticationContext("https://sts.example.com/adfs",false);
AuthenticationResult authenticationResult = await context.AcquireTokenAsync("http://example.com/api", certificate);
var token = authenticationResult.AccessToken;
【问题讨论】:
标签: c# .net console-application jwt adfs