private static TokenResponse GetToken() { var client = new OAuth2Client( new Uri("http://localhost:2727/token")); return client.RequestResourceOwnerPasswordAsync("bob", "bob").Result; }
private static TokenResponse GetToken(string tokenUrl) { var client = new OAuth2Client( new Uri(tokenUrl)); return client.RequestResourceOwnerPasswordAsync("cw", "cw").Result; }
private static TokenResponse RequestToken() { "Requesting token.".ConsoleYellow(); var client = new OAuth2Client( new Uri(Constants.AS.OAuth2TokenEndpoint), Constants.Clients.ResourceOwnerClient, Constants.Clients.ResourceOwnerClientSecret); TokenResponse response = null; try { response = client.RequestResourceOwnerPasswordAsync("pibline.authorization", "letmein","read").Result; client.RequestClientCredentialsAsync(); Console.WriteLine(" access token"); response.AccessToken.ConsoleGreen(); Console.WriteLine("\n refresh token"); response.RefreshToken.ConsoleGreen(); Console.WriteLine(); } catch (Exception ex) { Console.WriteLine(ex); } return response; }
static TokenResponse GetUserToken() { var client = new OAuth2Client( new Uri("https://localhost:44333/connect/token"), "carbon", "21B5F798-BE55-42BC-8AA8-0025B903DC3B"); return client.RequestResourceOwnerPasswordAsync("bob", "secret", "api1").Result; }
private static TokenResponse GetUserToken(String username, String password) { var client = new OAuth2Client( new Uri(ApplicationConstants.TokenEndpoint), ApplicationConstants.ConsoleAppClientId, ApplicationConstants.ConsoleAppClientSecret); return client.RequestResourceOwnerPasswordAsync(username, password, ApplicationScopes.ConsoleApp).Result; }
static TokenResponse GetUserTokenLock() { var client = new OAuth2Client( new Uri("https://HFL0100:44333/connect/token"), "carbon", "21B5F798-BE55-42BC-8AA8-0025B903DC3B",OAuth2Client.ClientAuthenticationStyle.PostValues); ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; return client.RequestResourceOwnerPasswordAsync("Davidao", "Davide1981!1", "api1").Result; }
static TokenResponse GetUserToken() { var client = new OAuth2Client( new Uri(Constants.AuthorizationUrl + "/connect/token"), "MyAppClientId", "21B5F798-BE55-42BC-8AA8-0025B903DC3B"); return client.RequestResourceOwnerPasswordAsync("testUser", "testPwd", "api1").Result; }
static TokenResponse RequestToken() { var client = new OAuth2Client( new Uri(Constants.TokenEndpoint), "roclient", "secret"); return client.RequestResourceOwnerPasswordAsync("bob", "bob", "read write").Result; }
static TokenResponse GetUserToken() { var client = new OAuth2Client( new Uri(ApplicationConstants.TokenEndpoint), ApplicationConstants.ClientIdConsoleApp, ApplicationConstants.ClientSecretConsoleApp); return client.RequestResourceOwnerPasswordAsync("itua.synergy", "asdfasdf", ApplicationScopes.ConsoleApp).Result; }
private static void ResourceOwnerFlow() { Console.WriteLine("Processing Resource owner password flow"); Console.WriteLine(""); Console.WriteLine(""); var client = new OAuth2Client(new Uri(Endpoint + "/issue/oidc/token"), ClientId, APIKey); var taks = client.RequestResourceOwnerPasswordAsync(UserName, Password, Scopes); taks.Wait(new TimeSpan(1, 0, 0)); var tokenResponse = taks.Result; Console.WriteLine("Access token received .. "); Console.WriteLine(""); Console.WriteLine(""); Console.WriteLine(tokenResponse.AccessToken); Console.WriteLine("Calling user info endpoint"); Console.WriteLine(""); Console.WriteLine(""); Console.WriteLine(""); var httpClient = new HttpClient { BaseAddress = new Uri(Endpoint + "/issue/oidc/userinfo") }; httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", tokenResponse.AccessToken); var response = httpClient.GetAsync("").Result; response.EnsureSuccessStatusCode(); var dictionary = response.Content.ReadAsAsync<Dictionary<string, string>>().Result; foreach (var pair in dictionary) { Console.WriteLine(pair.Key + " ----> " + pair.Value); } Console.WriteLine(""); Console.WriteLine(""); Console.WriteLine("Calling refresh token endpoint"); Console.WriteLine(""); Console.WriteLine(""); Console.WriteLine(""); Task<TokenResponse> refreshTokenResponse = client.RequestRefreshTokenAsync(tokenResponse.RefreshToken); refreshTokenResponse.Wait(); tokenResponse = refreshTokenResponse.Result; Console.WriteLine(""); Console.WriteLine(""); Console.WriteLine("Access token received using refresh token .. "); Console.WriteLine(""); Console.WriteLine(tokenResponse.AccessToken); Console.WriteLine(""); Console.WriteLine(""); RevokeToken(tokenResponse.AccessToken, "access_token"); Console.WriteLine(""); }
private async static Task ResourceOwnerFlow() { var oauthClient = new OAuth2Client(new Uri("http://localhost:1642/token")); var tokenResponse = oauthClient.RequestResourceOwnerPasswordAsync("cecil", "cecil").Result; var client = new HttpClient(); client.SetBearerToken(tokenResponse.AccessToken); var response = await client.GetStringAsync(new Uri("http://localhost:1642/api/secure/data")); Console.WriteLine(response); }
public async Task Should_Validate_And_Issue_Access_Token_When_Resource_Owner_Credentials_Are_Correct() { using (TestServer server = TestServer.Create<Startup>()) { OAuth2Client client = new OAuth2Client(new Uri("http://whatever:5000/token"), server.Handler); TokenResponse tokenResponse = await client.RequestResourceOwnerPasswordAsync("bob", "bob"); Assert.NotNull(tokenResponse); Assert.NotNull(tokenResponse.AccessToken); } }
static void Main(string[] args) { string tokenEndpoint = "http://localhost:53523/oauth/token"; OAuth2Client client = new OAuth2Client(new Uri(tokenEndpoint), "42ff5dad3c274c97a3a7c3d44b67bb42", "client123456"); TokenResponse tokenResponse = client.RequestResourceOwnerPasswordAsync("Tugberk", "user123456").Result; using (HttpClient httpClient = new HttpClient()) { httpClient.BaseAddress = new Uri("http://localhost:53523"); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokenResponse.AccessToken); HttpResponseMessage response = httpClient.GetAsync("api/users/me").Result; } }
public async Task Should_Call_The_Cars_Endpoint_With_A_Valid_Access_Token() { using (TestServer server = TestServer.Create<Startup>()) { OAuth2Client client = new OAuth2Client(new Uri("http://whatever:18008/token"), server.Handler); TokenResponse tokenResponse = await client.RequestResourceOwnerPasswordAsync("bob", "bob"); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://whatever:18008/api/cars"); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", tokenResponse.AccessToken); HttpResponseMessage response = await server.HttpClient.SendAsync(request); Assert.True(response.IsSuccessStatusCode); } }
public async Task RequestToken(string userName, string password) { var client = new OAuth2Client(new Uri(TokenUrl)); var token = await client.RequestResourceOwnerPasswordAsync(userName, password); if (token.IsError || token.IsHttpError) { throw new UnauthorizedAccessException(); } _token = token.AccessToken; SaveTokenToLocalStorage(token); }
private static TokenResponse GetToken() { try { var client = new OAuth2Client( new Uri("http://localhost/token")); return client.RequestResourceOwnerPasswordAsync("bob", "bob").Result; } catch (Exception ex) { string s = ex.Message; } return null; }
static TokenResponse RequestToken() { var client = new OAuth2Client( new Uri(Constants.TokenEndpoint), "roclient", "secret"); // idsrv supports additional non-standard parameters // that get passed through to the user service var optional = new Dictionary<string, string> { { "acr_values", "tenant:custom_account_store1 foo bar quux" } }; return client.RequestResourceOwnerPasswordAsync("bob", "bob", "read write", optional).Result; }
private static TokenResponse RequestToken() { "Requesting token.".ConsoleYellow(); var client = new OAuth2Client( new Uri(Constants.AS.OAuth2TokenEndpoint), Constants.Clients.ResourceOwnerClient, Constants.Clients.ResourceOwnerClientSecret); var response = client.RequestResourceOwnerPasswordAsync("bob", "abc!123", "read").Result; Console.WriteLine(" access token"); response.AccessToken.ConsoleGreen(); Console.WriteLine("\n refresh token"); response.RefreshToken.ConsoleGreen(); Console.WriteLine(); return response; }
public HttpResponseMessage Login([FromBody] LoginViewModel input) { var client = new OAuth2Client( new Uri("https://HFL0100:44333/connect/token"), "carbon", "21B5F798-BE55-42BC-8AA8-0025B903DC3B"); ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; // Ok(client.RequestResourceOwnerPasswordAsync(input.Username, input.Password, "api1 offline_access").Result); var response = client.RequestResourceOwnerPasswordAsync(input.Username, input.Password, "api1 api2 offline_access").Result; var response2 = new HttpResponseMessage(HttpStatusCode.OK); var cookie = new CookieHeaderValue("Halo-Secure", response.AccessToken); cookie.Expires = DateTimeOffset.Now.AddMinutes(1); cookie.Domain = null;//Request.RequestUri.Host; cookie.Path = "/"; cookie.HttpOnly = true; cookie.Secure = false; //in production is TRUE response2.Headers.AddCookies(new CookieHeaderValue[] { cookie }); return response2; }
static void Main(string[] args) { var oauthClient = new OAuth2Client(new Uri("http://localhost:5034/token"), "client", "secret"); try { var oauthresult = oauthClient.RequestResourceOwnerPasswordAsync("alice", "pass", "foo bar").Result; if (oauthresult.AccessToken != null) { Console.WriteLine(oauthresult.AccessToken); Console.WriteLine(); var client = new HttpClient(); client.SetBearerToken(oauthresult.AccessToken); var result = client.GetAsync("http://localhost:5034/test").Result; var json = result.Content.ReadAsStringAsync().Result; Console.WriteLine(json); } } catch(Exception ex) { Console.WriteLine("Error, {0}", ex.Message); } }
public async Task<TunesUser> SignInUser(string userName, string password) { TunesUser tunesUser = null; if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password)) { string strUrl = string.Format("{0}/token", this.ServiceUrl); var authClient = new OAuth2Client( new Uri(strUrl), "BSEtunes", OAuthClientSercret); try { this.TokenResponse = await authClient.RequestResourceOwnerPasswordAsync(userName, password); if (this.TokenResponse != null) { //if (this.TokenResponse..IsError) //{ // throw new UnauthorizedAccessException(this.m_strUnauthorizedAccessExceptionMessage); //} Windows.Storage.ApplicationData.Current.RoamingSettings.Values["username"] = userName; Windows.Security.Credentials.PasswordVault vault = new Windows.Security.Credentials.PasswordVault(); PasswordCredential passwordCredential = new PasswordCredential(PasswordVaultResourceName, userName, password); vault.Add(passwordCredential); if (passwordCredential != null) { tunesUser = this.User = new TunesUser { UserName = userName, Password = vault.Retrieve(PasswordVaultResourceName, passwordCredential.UserName).Password }; } } } catch (Exception) { throw new UnauthorizedAccessException(this.m_strUnauthorizedAccessExceptionMessage); } } else { throw new UnauthorizedAccessException(this.m_strUnauthorizedAccessExceptionMessage); } return tunesUser; }
private TokenResponse GetToken() { var client = new OAuth2Client(this.uriBuilder.TokenUri); return client.RequestResourceOwnerPasswordAsync( this.credentials.UserName, this.credentials.Password).Result; }
private TokenResponse GetToken() { OAuth2Client client = new OAuth2Client(new Uri("http://localhost:27809/token")); return client.RequestResourceOwnerPasswordAsync(Username, Password).Result; }
public TokenResponse GetToken(string userName, string password) { OAuth2Client client = new OAuth2Client(new Uri("http://localhost:45482/token")); return client.RequestResourceOwnerPasswordAsync(userName, password).Result; }