C# 如何在控制台应用程序中使用AD FS令牌
我有AD FS服务器,控制台应用程序和简单的网站,我可以用我的域帐户登录。 在我的控制台应用程序中,我从STS获得令牌。现在,我要和他一起登录到我要检查令牌的网站 我应该如何在WebClient、WebApiClient和WCF中使用此令牌? 我尝试用这个令牌在WCF中打开频道,并使用WebClient下载页面,但我得到了日志页面 此代币重要2周,如何提前取消此代币 这是我获得token works的代码:C# 如何在控制台应用程序中使用AD FS令牌,c#,console-application,C#,Console Application,我有AD FS服务器,控制台应用程序和简单的网站,我可以用我的域帐户登录。 在我的控制台应用程序中,我从STS获得令牌。现在,我要和他一起登录到我要检查令牌的网站 我应该如何在WebClient、WebApiClient和WCF中使用此令牌? 我尝试用这个令牌在WCF中打开频道,并使用WebClient下载页面,但我得到了日志页面 此代币重要2周,如何提前取消此代币 这是我获得token works的代码: string userName = "login"; string password =
string userName = "login";
string password = "pass";
string adfsAdr = @"https://domain/adfs/services/trust/13/usernamemixed";
string webPage = @"https://MyAspNetAppAdrs.com";
var factory = new Microsoft.IdentityModel.Protocols.WSTrust.WSTrustChannelFactory(
new UserNameWSTrustBinding(SecurityMode.TransportWithMessageCredential),
new EndpointAddress(adfsAdr));
factory.TrustVersion = TrustVersion.WSTrust13;
if (_factory.Credentials != null)
{
factory.Credentials.UserName.UserName = userName;
factory.Credentials.UserName.Password = password;
}
var rst = new RequestSecurityToken
{
RequestType = WSTrust13Constants.RequestTypes.Issue,
AppliesTo = new EndpointAddress(webPage),
KeyType = WSTrust13Constants.KeyTypes.Bearer,
};
var channel = factory.CreateChannel();
SecurityToken token = channel.Issue(rst);
你有没有设法让这一切进展顺利?我正在尝试完全相同的事情,也发现这非常令人困惑。你有没有设法让这一切进展顺利?我正在尝试完全相同的事情,也发现这非常令人困惑。