コード例 #1
0
        public SecurityToken RequestToken(string issuer, string appliesTo, RecordsManagerCredentials credentials)
        {
            var authContext = new AuthenticationContext(Constants.WAAD_AUTHORITY);

            AuthenticationResult result = null;

            // first, try to get a token silently
            try
            {
                result = authContext.AcquireTokenSilentAsync(appId, Constants.WAAD_CLIENTID).Result;
            }
            catch (AggregateException exc)
            {
                AdalException ex = exc.InnerException as AdalException;

                // There is no token in the cache; prompt the user to sign-in.
                if (ex != null && ex.ErrorCode != "failed_to_acquire_token_silently")
                {
                    throw;
                }
            }

            if (result == null)
            {
                result = this.RunSync(async() =>
                {
                    return(await authContext.AcquireTokenAsync(appId, Constants.WAAD_CLIENTID, new UserPasswordCredential(credentials.Username, credentials.Password)));
                });
            }

            return(new SecurityToken(result.AccessToken, result.AccessTokenType, result.ExpiresOn.DateTime));
        }
 public static RecordsManagerClient Create(string url, RecordsManagerCredentials credentials)
 {
     if (url.TrimEnd('/').Equals(Constants.AZ_URL_RLIL, StringComparison.OrdinalIgnoreCase))
     {
         return new RecordsManagerClient(url, credentials, new SecurityTokenRequestorAzureOAuth2());
     }
     else if (url.TrimEnd('/').Equals(Constants.AZ_URL_RLIL_TEST, StringComparison.OrdinalIgnoreCase))
     {
         return new RecordsManagerClient(url, credentials, new SecurityTokenRequestorAzureOAuth2(Constants.AZ_URL_RLIL_TEST));
     }
     else
     {
         return new RecordsManagerClient(url, credentials);
     }
 }
 public static RecordsManagerClient Create(string url, RecordsManagerCredentials credentials)
 {
     if (url.TrimEnd('/').Equals(Constants.AZ_URL_RLIL, StringComparison.OrdinalIgnoreCase))
     {
         return(new RecordsManagerClient(url, credentials, new SecurityTokenRequestorAzureOAuth2()));
     }
     else if (url.TrimEnd('/').Equals(Constants.AZ_URL_RLIL_TEST, StringComparison.OrdinalIgnoreCase))
     {
         return(new RecordsManagerClient(url, credentials, new SecurityTokenRequestorAzureOAuth2(Constants.AZ_APPID_RLIL_TEST)));
     }
     else if (url.TrimEnd('/').Equals(Constants.AZ_URL_RLIL_DEV, StringComparison.OrdinalIgnoreCase))
     {
         return(new RecordsManagerClient(url, credentials, new SecurityTokenRequestorAzureOAuth2(Constants.AZ_APPID_RLIL_DEV)));
     }
     else
     {
         return(new RecordsManagerClient(url, credentials));
     }
 }
        public GenericXmlSecurityToken RequestToken(string issuer, string appliesTo, RecordsManagerCredentials credentials)
        {
            var binding = (issuer.ToLower().StartsWith("https")) ? this.GetHttpsBinding() : this.GetHttpBinding();

            var address = new EndpointAddress(issuer);

            var factory = new WSTrustChannelFactory(binding, address);
            factory.TrustVersion = TrustVersion.WSTrust13;
            factory.Credentials.Windows.ClientCredential = credentials.GetCredential();

            var channel = factory.CreateChannel();

            var rst = new RequestSecurityToken(RequestTypes.Issue)
            {
                AppliesTo = new EndpointAddress(appliesTo)
            };

            RequestSecurityTokenResponse rstr = null;

            return channel.Issue(rst, out rstr) as GenericXmlSecurityToken;
        }
        public GenericXmlSecurityToken RequestToken(string issuer, string appliesTo, RecordsManagerCredentials credentials)
        {
            var binding = (issuer.ToLower().StartsWith("https")) ? this.GetHttpsBinding() : this.GetHttpBinding();

            var address = new EndpointAddress(issuer);

            var factory = new WSTrustChannelFactory(binding, address);

            factory.TrustVersion = TrustVersion.WSTrust13;
            factory.Credentials.Windows.ClientCredential = credentials.GetCredential();

            var channel = factory.CreateChannel();

            var rst = new RequestSecurityToken(RequestTypes.Issue)
            {
                AppliesTo = new EndpointAddress(appliesTo)
            };

            RequestSecurityTokenResponse rstr = null;

            return(channel.Issue(rst, out rstr) as GenericXmlSecurityToken);
        }