コード例 #1
0
 public static AssertionCredential ToAssertion(this Azure.AssertionCredential ac)
 {
     return(new AssertionCredential()
     {
         Assertion = ac.Assertion
     });
 }
コード例 #2
0
        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));
        }
コード例 #3
0
 public async Task <Azure.AssertionCredential> Token(string serviceRealm)
 {
     if (null == assertionCredential || assertionCredential.Expired(Skew))
     {
         assertionCredential = await token(serviceRealm);
     }
     return(assertionCredential);
 }
コード例 #4
0
//		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));
        }