public static AssertionCredential ToAssertion(this Azure.AssertionCredential ac) { return(new AssertionCredential() { Assertion = ac.Assertion }); }
private Task <Azure.AssertionCredential> token(string serviceRealm) { Trace.TraceInformation("Request Token"); Azure.AssertionCredential assertionCredential = null; IList <Azure.IdentityProviderDescriptor> idpdList = authenticationContext.GetProviders(serviceRealm); foreach (Azure.IdentityProviderDescriptor idpd in idpdList) { foreach (string emailAddressSuffix in idpd.EmailAddressSuffixes) { if (string.Compare(credential.Resource, emailAddressSuffix, StringComparison.OrdinalIgnoreCase) == 0) { // Invoke AuthenticationContext.AcquireToken to obtain an AssertionCredential to access the service. // It will use previously-created KerberosCredential or UsernamePasswordCredential to authenticate with the selected identity provider. Trace.TraceInformation("Using identity provider: {0}", idpd.Name); if (credential is Azure.UsernamePasswordCredential) { Trace.TraceInformation("Using username-password credentials: {0}", ((Azure.UsernamePasswordCredential)credential).Name); } if (credential is Azure.KerberosCredential) { Trace.TraceInformation("Using Kerberos credentials: {0}", WindowsIdentity.GetCurrent().Name); } assertionCredential = authenticationContext.AcquireToken(serviceRealm, credential); Trace.TraceInformation("Received token result from: {0}", assertionCredential.Resource); return(Task.FromResult <Azure.AssertionCredential>(assertionCredential)); } } } throw new InvalidOperationException(string.Format("[{0}] is not a supported domain for any identity providers on the target service realm : {1}", credential.Resource, serviceRealm)); }
public async Task <Azure.AssertionCredential> Token(string serviceRealm) { if (null == assertionCredential || assertionCredential.Expired(Skew)) { assertionCredential = await token(serviceRealm); } return(assertionCredential); }
// public static string Oauth2AuthorizationHeader(this AssertionCredential ac) { return "Bearer"; } public static bool Expired(this Azure.AssertionCredential ac, TimeSpan skew) { DateTime now = DateTime.UtcNow; return(ac.Expires < now.Subtract(skew) || ac.Created > now.Add(skew)); }