I'm using Windows Authentication.
I need to log into a service. It requires authentication using an ICredentials
object, but would rather avoid asking for the user to enter their credentials again.
Is there a way to get the ICredentials
from the currently logged in user?
The service is the TFS SDK.
Controller in MVC has a property User
which is IPrincipal
.
http://msdn.microsoft.com/en-us/library/system.web.mvc.controller.user%28v=vs.108%29.aspx
IPrincipal
has an Identity
property
http://msdn.microsoft.com/en-us/library/system.security.principal.iprincipal.identity%28v=vs.110%29.aspx
which is of type IIdentity
http://msdn.microsoft.com/en-us/library/system.security.principal.iidentity%28v=vs.110%29.aspx
If you're using Windows Authentication the actual instance will be of type WindowsIdentity
http://msdn.microsoft.com/en-us/library/system.security.principal.windowsidentity%28v=vs.110%29.aspx
Hopefully it will contain all the credential information you need.
Also, you might want to try:
Uri uri = new Uri("http://tempuri.org/");
ICredentials credentials = CredentialCache.DefaultNetworkCredentials;
NetworkCredential credential = credentials.GetCredential(uri, "Basic");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With