コード例 #1
0
        public override Task <IAccessToken> Authenticate(IAzureAccount account, IAzureEnvironment environment, string tenant, SecureString password, string promptBehavior, Task <Action <string> > promptAction, IAzureTokenCache tokenCache, string resourceId)
        {
            var audience = environment.GetEndpoint(resourceId);
            var context  = new AuthenticationContext(
                AuthenticationHelpers.GetAuthority(environment, tenant),
                environment?.OnPremise ?? true,
                tokenCache as TokenCache ?? TokenCache.DefaultShared);
            var result = context.AcquireTokenAsync(audience, AuthenticationHelpers.PowerShellClientId, new UserPasswordCredential(account.Id, password));

            return(AuthenticationResultToken.GetAccessTokenAsync(result));
        }
コード例 #2
0
        public async override Task <IAccessToken> Authenticate(IAzureAccount account, IAzureEnvironment environment, string tenant, SecureString password, string promptBehavior, Task <Action <string> > promptAction, IAzureTokenCache tokenCache, string resourceId)
        {
            var auth     = new AuthenticationContext(AuthenticationHelpers.GetAuthority(environment, tenant), environment?.OnPremise ?? true, tokenCache as TokenCache ?? TokenCache.DefaultShared);
            var response = await auth.AcquireTokenAsync(
                environment.GetEndpoint(resourceId),
                AuthenticationHelpers.PowerShellClientId,
                new Uri(AuthenticationHelpers.PowerShellRedirectUri),
                new PlatformParameters(AuthenticationHelpers.GetPromptBehavior(promptBehavior), new ConsoleParentWindow()),
                UserIdentifier.AnyUser,
                AuthenticationHelpers.EnableEbdMagicCookie);

            account.Id = response?.UserInfo?.DisplayableId;
            return(AuthenticationResultToken.GetAccessToken(response));
        }