private static async Task <IdentityModel.Client.IdentityModelExtensions.TokenResponse> _RetrieveAccessToken(string uName, string pWd, DiscoveryResponse disco) { var client = new HttpClient(); IdentityModel.Client.IdentityModelExtensions.TokenResponse tokenResponse = null; try { //var disco = await getDisco(); string[] temp = uName.Split(new string[] { "\\" }, StringSplitOptions.RemoveEmptyEntries); uName = temp.Length > 1 ? temp[1] : temp[0]; var tokenRequest = new PasswordTokenRequest { Address = disco.TokenEndpoint, ClientId = CLIENT_ID, ClientSecret = CLIENT_SECRET, UserName = uName, Password = pWd }; tokenResponse = await client.RequestPasswordTokenAsync(tokenRequest).ConfigureAwait(false); if (tokenResponse.IsError) { throw new Exception(tokenResponse.Error); } } catch (Exception e) { throw e; } return(tokenResponse); }
public static IdentityModel.Client.IdentityModelExtensions.TokenResponse RetrieveAccessToken(string login, string password, DiscoveryResponse tokenEndpoint) { IdentityModel.Client.IdentityModelExtensions.TokenResponse token = null; Task.Run(async() => { token = await _RetrieveAccessToken(login, password, tokenEndpoint); }).Wait(); return(token); }
public User DGALogin(string userName, string password) { var accountName = string.Empty; accountName = string.Format("{0}\\{1}", Take2Domain, userName); IdentityModel.Client.IdentityModelExtensions.TokenResponse token = Take2RetrieveToken(accountName, password); DGATokenResponse dgaToken = null; if (token != null) { dgaToken = Take2RetrieveDGAToken(token.AccessToken); } if (dgaToken != null) { var identifiedUser = CreateVirtualUser(dgaToken, userName); var result = AuthenticationManager.LoginVirtualUser(identifiedUser); } var user = AuthenticationManager.GetActiveUser(); //this.pipelineService.RunLoggedIn(user); return(user); }
private IdentityModel.Client.IdentityModelExtensions.TokenResponse Take2RetrieveToken(string login, string password) { DiscoveryResponse disco = Client.GetDisco(); IdentityModel.Client.IdentityModelExtensions.TokenResponse token = null; token = Client.RetrieveAccessToken(login, password, disco); return(token); }