Skip to content

Instantly share code, notes, and snippets.

@MiddleTommy
Created November 13, 2016 01:13
Show Gist options
  • Save MiddleTommy/970f0b49665c40fa314ebc49f0b1fd78 to your computer and use it in GitHub Desktop.
Save MiddleTommy/970f0b49665c40fa314ebc49f0b1fd78 to your computer and use it in GitHub Desktop.
C# Auth0.Core login/register Samples
using System;
using System.Threading.Tasks;
using Auth0.AuthenticationApi;
using Auth0.AuthenticationApi.Models;
namespace Cards.Documents.Authorization
{
public class Auth0Example
{
string auth0domain;
string auth0clientId;
public async Task<Auth0.Core.User> LoginAuth0(string username, string password)
{
var domain = new Uri($"https://{auth0domain}/");
var client = new AuthenticationApiClient(domain);
var req = new AuthenticationRequest();
req.Username = username;
req.Password = password;
req.ClientId = auth0clientId;
req.Scope = "openid";
req.Connection = "Username-Password-Authentication";
var res = await client.AuthenticateAsync(req);
var token = res.IdToken;
if (!string.IsNullOrWhiteSpace(token))
{
var auser = await client.GetTokenInfoAsync(token);
return auser;
}
return null;
}
public async Task RegisterAuth0(string email, string password)
{
var domain = new Uri($"https://{auth0domain}/");
var client = new AuthenticationApiClient(domain);
var req = new SignupUserRequest();
req.Email = email;
req.Password = password;
req.ClientId = auth0clientId;
req.Connection = "Username-Password-Authentication";
var t = await client.SignupUserAsync(req);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment