Beispiel #1
0
        public void TestSplitComplex()
        {
            var split = ScopeUtils.Split("scope1 r2/scope https://foo.com/.default").ToList();

            Assert.AreEqual(3, split.Count);
            Assert.AreEqual("scope1", split[0]);
            Assert.AreEqual("r2/scope", split[1]);
            Assert.AreEqual("https://foo.com/.default", split[2]);
        }
Beispiel #2
0
        public void TestSplitSimple()
        {
            var split = ScopeUtils.Split("a b c").ToList();

            Assert.AreEqual(3, split.Count);
            Assert.AreEqual("a", split[0]);
            Assert.AreEqual("b", split[1]);
            Assert.AreEqual("c", split[2]);
        }
Beispiel #3
0
        internal TokenResponse(
            MsalTokenResponse mtr,
            ITimeService timeService = null)
        {
            var timeSvc = timeService ?? new TimeService();

            AccessToken  = mtr.AccessToken;
            RefreshToken = mtr.RefreshToken;
            IdToken      = new IdToken(mtr.IdToken);
            Scopes       = ScopeUtils.Split(mtr.Scope);
            var clientInfo = ClientInfo.Create(EncodingUtils.Base64UrlDecodeUnpadded(mtr.ClientInfo));

            ExpiresOn         = timeSvc.GetUtcNow().AddSeconds(mtr.ExpiresIn);
            ExtendedExpiresOn = timeSvc.GetUtcNow().AddSeconds(mtr.ExtendedExpiresIn);

            Uid  = clientInfo.UniqueObjectIdentifier;
            Utid = clientInfo.UniqueTenantIdentifier;
        }
Beispiel #4
0
        internal TokenResponse(
            MsalTokenResponse mtr,
            ITimeService timeService = null)
        {
            var timeSvc = timeService ?? new TimeService();

            AccessToken  = mtr.AccessToken;
            RefreshToken = mtr.RefreshToken;
            IdToken      = string.IsNullOrWhiteSpace(mtr.IdToken) ? null : new IdToken(mtr.IdToken);
            Scopes       = ScopeUtils.Split(mtr.Scope);
            ClientInfo clientInfo = string.IsNullOrWhiteSpace(mtr.ClientInfo) ? null : ClientInfo.Create(mtr.ClientInfo);

            ExpiresOn         = timeSvc.GetUtcNow().AddSeconds(mtr.ExpiresIn);
            ExtendedExpiresOn = timeSvc.GetUtcNow().AddSeconds(mtr.ExtendedExpiresIn);

            Uid  = clientInfo?.UniqueObjectIdentifier;
            Utid = clientInfo?.UniqueTenantIdentifier;
        }
Beispiel #5
0
        public TokenResponse(
            IdToken idToken,
            Credential accessToken,
            Credential refreshToken)
        {
            IdToken = idToken ?? new IdToken(string.Empty);
            if (accessToken != null)
            {
                AccessToken       = accessToken.Secret;
                ExpiresOn         = accessToken.ExpiresOn;
                ExtendedExpiresOn = accessToken.ExtendedExpiresOn;
                Scopes            = ScopeUtils.Split(accessToken.Target);
            }

            if (refreshToken != null)
            {
                RefreshToken = refreshToken.Secret;
            }
        }
        private async Task <string> AuthenticationCallbackAsync(
            string authority,
            string resource,
            string scope)
        {
            var msalConfiguration = new MsalClientConfiguration();
            var pca = new PublicClientApplication(msalConfiguration);
            //var authContext = new AuthenticationContext(authority, keyVaultTokenCache);

            var authParameters = new AuthenticationParameters
            {
                Authority = authority,
                ClientId  = _config.ClientId,
            };

            authParameters.AddScopes(ScopeUtils.Split(scope));
            authParameters.AddScope("https://vault.azure.net/.default");

            switch (_config.AuthType)
            {
            case KeyVaultAuthenticationType.ClientCertificate:
                var cert = CertificateHelper.FindCertificateByThumbprint(_config.CertThumbprint);
                authParameters.Certificate       = cert;
                authParameters.AuthorizationType = AuthorizationType.Certificate;

                // authContext.AcquireTokenAsync(resource, _assertionCert));
                break;

            case KeyVaultAuthenticationType.UserCredential:
                authParameters.AuthorizationType = AuthorizationType.WindowsIntegratedAuth;
                //authResult = await authContext.AcquireTokenAsync(resource, _config.ClientId, new UserCredential());
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            var authResult = await pca.AcquireTokenSilentlyAsync(authParameters, CancellationToken.None)
                             .ConfigureAwait(false);

            return(authResult?.AccessToken);
        }
Beispiel #7
0
        public void TestSplitEmpty()
        {
            var split = ScopeUtils.Split(string.Empty).ToList();

            Assert.AreEqual(0, split.Count);
        }
Beispiel #8
0
        public void TestSplitWhitespace()
        {
            var split = ScopeUtils.Split("    ").ToList();

            Assert.AreEqual(0, split.Count);
        }
Beispiel #9
0
        public void TestSplitNull()
        {
            var split = ScopeUtils.Split(null).ToList();

            Assert.AreEqual(0, split.Count);
        }