protected void InitializeAuth0Client() { this.auth0Config = this.configurationRepository.GetConfiguration(); if (!this.auth0Config.IsValid) { return; } try { var clientsIds = this.auth0Config.ClientId.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); var clientsSecrets = this.auth0Config.ClientSecret.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); var clientIdIndex = Array.IndexOf(clientsIds, Utils.GetClaimsValue(ClientIdClaimsType)); // if clientID was not found, use the first one configured on central admin if (clientIdIndex == -1) { clientIdIndex = 0; } this.auth0Client = new Auth0.Client( clientsIds[clientIdIndex], clientsSecrets[clientIdIndex], this.auth0Config.Domain); } catch (Exception ex) { Auth0LoggingService.WriteError(ex.ToString()); } this.alwaysResolveValue = true; //this.auth0Config.AlwaysResolveUserInput; this.pickerEntityGroupName = this.auth0Config.PickerEntityGroupName; }
private void OnSignIn(object sender, EventArgs e) { Log("Signing in with {0}...", textLoginUsername.Text); Log(" > Connection: {0}", textLoginConnection.Text); Log(" > Client Id: {0}", textLoginClientId.Text); Log(" > Domain: {0}", textLoginDomain.Text); try { var client = new Auth0.Client(textLoginClientId.Text, textLoginDomain.Text); var tokens = client.LoginUser(textLoginUsername.Text, textLoginPassword.Text, textLoginConnection.Text, "openid profile"); Log("Login success!"); Log(" > Id Token: {0}", tokens.IdToken); Log(" > Access Token: {0}", tokens.AccessToken); var jwt = JWT.JsonWebToken.Decode(tokens.IdToken, "", false); var jwtObj = Newtonsoft.Json.JsonConvert.DeserializeObject(jwt); Log(" > JWT:\r\n\r\n{0}\r\n", Newtonsoft.Json.JsonConvert.SerializeObject(jwtObj, Newtonsoft.Json.Formatting.Indented)); } catch (Exception ex) { Log("Login failed!"); Log(" > Error: {0}", ex.Message); } }
private void OnSearch(object sender, EventArgs e) { Log("Searching for {0}...", textSearchUserId.Text); Log(" > Client Id: {0}", textSearchClientId.Text); Log(" > Domain: {0}", textSearchDomain.Text); try { var client = new Auth0.Client(textSearchClientId.Text, textSearchClientSecret.Text, textSearchDomain.Text); var user = client.GetUser(textSearchUserId.Text); if (user != null) { Log("User found!"); Log(" > Data:\r\n\r\n{0}\r\n", Newtonsoft.Json.JsonConvert.SerializeObject(user, Newtonsoft.Json.Formatting.Indented)); } else { Log("User not found!"); } } catch (Exception ex) { Log("User not found!"); Log(" > Error: {0}", ex.Message); } }
static void Main(string[] args) { Console.WriteLine("Press ENTER to call the API."); Console.ReadLine(); var client = new Auth0.Client("aJ720Y4ZCU97EsAfNabs4lLW3GzfTGE0", "tenant.auth0.com"); var token = client.LoginUser("*****@*****.**", "abc", "Username-Password-Authentication", "openid profile"); var apiClient = new HttpClient(); apiClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.IdToken); var response = apiClient.GetAsync("http://localhost:25100/api/sample").Result; var content = response.Content.ReadAsAsync<IEnumerable<ClaimItem>>().Result; Console.WriteLine("Call complete. Data received:"); foreach (var item in content) Console.WriteLine(" > {0}: {1}", item.Type, item.Value); Console.ReadLine(); }
protected void InitializeApiClient(Uri context) { // Already initialized. if (this.client != null && this.clientContext == context) { return; } // Invalid. this.configuration = this.configurationRepository.GetConfiguration(); if (!this.configuration.IsValid) { logger.ConfigurationInvalid(); return; } try { // Split multiple values if any. var domains = this.configuration.Domain.Split(new string[] { Environment.NewLine, ";", "," }, StringSplitOptions.None); var clientsIds = this.configuration.ClientId.Split(new string[] { Environment.NewLine, ";", "," }, StringSplitOptions.None); var clientsSecrets = this.configuration.ClientSecret.Split(new string[] { Environment.NewLine, ";", "," }, StringSplitOptions.None); // Try to find the current client. var clientIdIndex = Array.IndexOf(clientsIds, Utils.GetClaimsValue(DefaultClaimTypes.ClientId)); if (clientIdIndex == -1) { var webApplicationClientId = GetWebApplicationClientId(context); if (webApplicationClientId != null) { clientIdIndex = Array.IndexOf(clientsIds, webApplicationClientId); } logger.ClientIdFound(context, webApplicationClientId); if (clientIdIndex == -1) { throw new InvalidOperationException("Unable to find client ID for: " + context.ToString()); } } // Get values. var clientId = clientsIds[clientIdIndex]; var domain = domains[clientIdIndex]; // Initialize client. this.client = new Auth0.Client( clientId, clientsSecrets[clientIdIndex], domain, diagnostics: DiagnosticsHeader.Default .AddEnvironment("SharePoint", "2013") .AddEnvironment("ClaimsProvider", GetType().Assembly.FullName)); this.clientContext = context; // Log complete. logger.ConfigurationInitialized(context, domain, clientId); } catch (Exception ex) { logger.ConfigurationError(ex); throw; } this.alwaysResolveValue = true; //this.auth0Config.AlwaysResolveUserInput; this.pickerEntityGroupName = this.configuration.PickerEntityGroupName; }