using Microsoft.IdentityModel.Clients.ActiveDirectory; using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Tango.Core { public class ActiveDirectoryAuthProvider : SqlAuthenticationProvider { public override async Task AcquireTokenAsync(SqlAuthenticationParameters parameters) { AuthenticationContext authContext = new AuthenticationContext(parameters.Authority); authContext.CorrelationId = parameters.ConnectionId; AuthenticationResult result; result = await authContext.AcquireTokenAsync( parameters.Resource, "ec612854-7abc-457b-808a-5d0c5ba80c57", new Uri("http://www.google.com"), new PlatformParameters(PromptBehavior.Auto), new UserIdentifier( parameters.UserId, UserIdentifierType.RequiredDisplayableId)); return new SqlAuthenticationToken(result.AccessToken, result.ExpiresOn); } public override bool IsSupported(SqlAuthenticationMethod authenticationMethod) { return authenticationMethod == SqlAuthenticationMethod.ActiveDirectoryInteractive; } } }