Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Authenticating against AD FS from a .Net 4.5 Console App

Tags:

.net-4.5

wif

adfs

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

like image 373
Gavin Avatar asked Jan 25 '13 12:01

Gavin


1 Answers

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).

like image 99
leastprivilege Avatar answered Sep 20 '22 12:09

leastprivilege