Authenticating against AD FS from a .Net 4.5 Conso

2019-03-20 17:35发布

I'm in the process of getting my head round using AD FS to authenticate a user in a .NET 4.5 app. I can't find any examples of requesting/receiving the token from a console app and converting that token into a ClaimsPrinciple. The only examples I can find are WCF configuration based and I would really like to see the actual code that can do this in it's simplest form.

I've installed AD FS and think I've got it configured ready to receive requests. I've created a relying party, given it a key and assigned a couple of claims to it.

Can anyone point me in the right direction or what I need to do now in my console app to send authentication requests to it?

Thanks

1条回答
我欲成王,谁敢阻挡
2楼-- · 2019-03-20 18:07

The easiest way is to use the WSTrustChannelFactory from .NET 4.5.

See the RequestSecurityToken method here: http://leastprivilege.com/2012/11/16/wcf-and-identity-in-net-4-5-external-authentication-with-ws-trust/

After you have the token you run it through the corresponding token handler to turn it into a ClaimsPrincipal.

I have helper methods and bindings in my library on github: https://github.com/thinktecture/Thinktecture.IdentityModel.45

(look for the WCF folder, WSTrustClient and the Extensions folder).

查看更多
登录 后发表回答