コード例 #1
0
ファイル: WebAPI.cs プロジェクト: kzeitz/QueZed
 public WebAPI(Uri uri, string api, AssertionCredential assertionCredential)
 {
     if (null == uri)
     {
         throw new NullReferenceException("URI cannot be null.");
     }
     if (null == assertionCredential)
     {
         throw new NullReferenceException("Credential cannot be null.");
     }
     if (string.IsNullOrEmpty(api))
     {
         throw new NullReferenceException("API cannot be null or empty.");
     }
     this.uri = uri;
     this.api = api;
     this.assertionCredential = assertionCredential;
 }
コード例 #2
0
        public async Task LoginAsync(string username, string password) {
            const string Scheme = "Bearer";

            await Task.Run(() => {
                _context = new Microsoft.WindowsAzure.ActiveDirectory.Authentication.AuthenticationContext(Tenant.ToString());

                var providers = _context.GetProviders(Realm);
                var identity = providers.First(x => x.Name.Equals(Provider, StringComparison.InvariantCultureIgnoreCase));

                var credential = new UsernamePasswordCredential(identity.Name, username, password);

                _credential = _context.AcquireToken(Realm, identity, credential);

                var token = _credential.AsSecurityToken();
                var header = _credential.CreateAuthorizationHeader();

                _claims = token.Claims;

                _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(Scheme, _credential.Assertion);

            }).ConfigureAwait(false);
        }
コード例 #3
0
ファイル: WebAPI.cs プロジェクト: kzeitz/QueZed
 public WebAPIGet(Uri uri, string api, AssertionCredential assertionCredential) : base(uri, api, assertionCredential)
 {
 }
コード例 #4
0
 internal static JwtSecurityToken AsSecurityToken(this AssertionCredential self)
 {
     return(new JwtSecurityToken(self.Assertion));
 }