Beispiel #1
0
        public static async Task <AzureDevOpsUserContext> GetUserContext(CancellationToken cancelToken = default)
        {
            const string          aadAuthority   = "https://login.windows.net/microsoft.com";
            const string          aadResource    = "499b84ac-1321-427f-aa17-267ca6975798";
            const string          aadClientId    = "872cd9fa-d31f-45e0-9eab-6e460a02d1f1";
            AuthenticationContext authCtx        = new AuthenticationContext(aadAuthority);
            UserCredential        userCredential = new UserCredential();

            AzureDevOpsUserContext result = new AzureDevOpsUserContext
            {
                AuthenticationResult = await authCtx.AcquireTokenAsync(aadResource, aadClientId, userCredential),
                VssAadCredential     = new VssAadCredential(new VssAadToken(authCtx, userCredential))
            };

            using (VssConnection connection = new VssConnection(new Uri("https://app.vssps.visualstudio.com"), result.VssAadCredential))
            {
                AccountHttpClient accountsClient = await connection.GetClientAsync <AccountHttpClient>(cancelToken);

                result.Accounts = await accountsClient.GetAccountsByMemberAsync(connection.AuthorizedIdentity.Id, cancellationToken : cancelToken);
            }

            return(result);
        }
Beispiel #2
0
 public AzureDevOpsClient(Uri accountUri, AzureDevOpsUserContext userContext)
 {
     this.connection = new VssConnection(accountUri, userContext.VssAadCredential);
 }