gpt4 book ai didi

c# - ID3242 : The security token could not be authenticated or authorized

转载 作者:行者123 更新时间:2023-11-30 18:20:28 26 4
gpt4 key购买 nike

目前我正在处理一个项目,我的应用程序必须使用 ADFS 进行验证才能登录。

我找到了一些从 ADFS 获取 token 的代码,但它一直给我上面的错误,但没有对错误进行任何好的描述。

这是我使用的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceModel;
using System.ServiceModel.Security;
using System.Net;
using System.IdentityModel.Protocols.WSTrust;
using System.IdentityModel.Tokens;

namespace ADFS_token_test_3
{
class Program
{
static void Main(string[] args)
{
go();
}

static public EndpointAddress ep;
static public WSTrustChannelFactory factory;

public static string go()
{
WS2007HttpBinding binding = new WS2007HttpBinding(SecurityMode.TransportWithMessageCredential);
binding.Security.Message.EstablishSecurityContext = false;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;

binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
ep = new EndpointAddress("https://companyname.nl/adfs/services/trust/13/usernamemixed");

factory = new WSTrustChannelFactory(binding, ep);
factory.TrustVersion = TrustVersion.WSTrust13;

factory.Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
factory.Credentials.UserName.UserName = "username";
factory.Credentials.UserName.Password = "password";

var rst = new RequestSecurityToken
{
RequestType = RequestTypes.Issue,
AppliesTo = new EndpointReference("https://companyname.nl/adfs/services/trust/13/usernamemixedr"),
KeyType = KeyTypes.Bearer,
};

IWSTrustChannelContract channel = factory.CreateChannel();
// Error line
GenericXmlSecurityToken genericToken = channel.Issue(rst)
as GenericXmlSecurityToken;

return genericToken.TokenXml.InnerXml.ToString();
}
}
}

错误发生在错误注释的行。

有人知道吗?

最佳答案

检查是否可以到达您的 CRL 分发点。

我在某些 ADFS 单一登录 Web 应用程序中遇到过该问题。ADFS 使用 PKI 证书(例如用于签署 token )。这些证书通常具有必须可访问的 CRL(证书吊销列表)。如果无法检查撤销列表,您往往会出现上述错误信息。对我来说,它是位于我的应用程序和 CDP(CRL 分发点)服务器之间的防火墙。

附言。您可以在查看证书本身的详细信息时验证 CDP。

关于c# - ID3242 : The security token could not be authenticated or authorized,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37270974/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com