예제 #1
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            var ilogger = new DefaultUsageLogger(Information, Warning, Error);

            var config = new PublicClientApplicationOptions
            {
                AzureCloudInstance   = AzureCloudInstance.AzureUsGovernment,
                AadAuthorityAudience = AadAuthorityAudience.AzureAdMyOrg,
                ClientId             = ClientId,
                TenantId             = TenantId,
                RedirectUri          = ResourceUri
            };


            App = PublicClientApplicationBuilder.CreateWithApplicationOptions(config)
                  .WithAuthority(config.AzureCloudInstance, config.AadAuthorityAudience)                              // work around to MSAL.NET bug #969
                  .Build();

            var tokens = AcquireATokenFromCacheOrUsernamePasswordAsync(new string[] { "User.Read", "User.ReadBasic.All" }).GetAwaiter().GetResult();
        }
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            var useInteractiveLogin = true;
            var ilogger             = new DefaultUsageLogger(Information, Warning, Error);

            if (Scopes == null || !Scopes.Any())
            {
                useInteractiveLogin = false;
                Scopes = new string[] { AzureADConstants.MSGraphScope };
            }

            AuthenticationSettings.PostLogoutRedirectURI = this.ResourceUri ?? AzureADConstants.GraphResourceId;
            AuthenticationSettings.MSALScopes            = Scopes;

            // Get back the Access Token and the Refresh Token
            var AzureADCache = new AzureADv2TokenCache(AuthenticationSettings, ilogger, useInteractiveLogin);

            AzureADALConnection.CurrentConnection = new AzureADALConnection(AzureADCache, AuthenticationSettings, ilogger);

            // Write Tokens to Console
            WriteObject(AzureADALConnection.CurrentConnection.AuthenticationResult);
        }