Nexaas.ID.Client 1.0.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package Nexaas.ID.Client --version 1.0.3
NuGet\Install-Package Nexaas.ID.Client -Version 1.0.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Nexaas.ID.Client" Version="1.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Nexaas.ID.Client --version 1.0.3
#r "nuget: Nexaas.ID.Client, 1.0.3"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Nexaas.ID.Client as a Cake Addin
#addin nuget:?package=Nexaas.ID.Client&version=1.0.3

// Install Nexaas.ID.Client as a Cake Tool
#tool nuget:?package=Nexaas.ID.Client&version=1.0.3

Nexaas.Id.Client

This is .NET client for the Nexaas ID API.

Nexaas.Id.Client doesn't store any data. The application must authenticate users using Nexaas.Id.Client methods.

Installation

This package is available through Nuget Packages: https://www.nuget.org/packages/Nexaas.ID.Client/

Package Manager

Install-Package Nexaas.ID.Client

.NET CLI

dotnet add package Nexaas.ID.Client

.Paket Cli

paket add Nexaas.ID.Client

Dependencies

.NET Standard >=2.0, Newtonsoft.Json >= 11.0.2

You can check supported frameworks here:

https://docs.microsoft.com/pt-br/dotnet/standard/net-standard

https://www.newtonsoft.com/json

Configuration

Create a new application

Go to https://id.nexaas.com/applications and create a new application in your Nexaas ID account.

Setup your environment

var nexaasId = NexaasID.Production(
  "your client id", 
  "your client secret", 
  "your application callback uri");

Get Nexaas ID login url

var url = nexaasId.GetAuthorizeUrl();

Get Nexaas ID authorization token

BaseResponse<AuthTokenResponse> response = await nexaasId.GetAuthorizationToken("code");

Get Profile info

BaseResponse<Profile> response = await nexaasId.GetProfile("access_token");

Get Profile professional info

BaseResponse<ProfessionalInfo> response = await nexaasId.GetProfessionalInfo("access_token");

Get Profile contacts

BaseResponse<Contacts> response = await nexaasId.GetContacts("access_token");

Get Profile emails

BaseResponse<Emails> response = await nexaasId.GetEmails("access_token");

Invite to application

BaseResponse<ApplicationInvitiationResponse> response = 
  await nexaasId.InviteToApplication(new ApplicationInvitiationRequest("invited_email", "access_token"));

Asp.Net Core Mvc usage example

Source code example

Setup Startup.cs
public class Startup
{
    public Startup(IConfiguration configuration, IHostingEnvironment env)
    {
        Configuration = configuration;
        Env = env;
    }

    public IConfiguration Configuration { get; }
    public IHostingEnvironment Env { get;  }

    public void ConfigureServices(IServiceCollection services)
    {
        //Retrive Nexaas ID application configuration
        var clientId = Configuration.GetSection("NexaasIDConfig:ClientId").Value;
        var clientSecret = Configuration.GetSection("NexaasIDConfig:clientSecret").Value;
        var redirectUri = Configuration.GetSection("NexaasIDConfig:RedirectUri").Value;

        //Setup Nexaas.ID.Client
        var nexaasId = Env.IsProduction()
            ? NexaasID.Production(clientId, clientSecret, redirectUri)
            : NexaasID.Sandbox(clientId, clientSecret, redirectUri);

        //Add Nexaas.ID.Client in DI container
        services.AddSingleton(nexaasId);

        services.Configure<CookiePolicyOptions>(options =>
        {
            options.CheckConsentNeeded = context => true;
            options.MinimumSameSitePolicy = SameSiteMode.None;
        });

        //Configure cookie authentication
        services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
            .AddCookie(options =>
            {
                options.Cookie.Name = "NexaasIdCookie";
                options.ExpireTimeSpan = TimeSpan.FromSeconds(7200);
                options.LoginPath = "/auth";
            });

        services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
            app.UseHsts();
        }

        app.UseHttpsRedirection();
        app.UseAuthentication();
        app.UseStaticFiles();
        app.UseCookiePolicy();

        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");
        });
    }
}
Add controller to handle authentication

public class AuthController : Controller
{
    private readonly NexaasID _nexaasId;

    /// Inject NexaasID
    public AuthController(NexaasID nexaasId)
    {
        _nexaasId = nexaasId;
    }

    /// <summary>
    /// Get and redirect to Nexaas ID authorize url
    /// </summary>
    /// <returns>IActionResult</returns>
    [AllowAnonymous, HttpGet]
    public IActionResult Index() => Redirect(_nexaasId.GetAuthorizeUrl());

    /// <summary>
    /// Action callback, invoked by Nexaas ID after user authentication
    /// </summary>
    /// <param name="code"></param>
    /// <returns>IActionResult</returns>
    [HttpGet]
    public async Task<IActionResult> Signin(string code)
    {
        if(string.IsNullOrWhiteSpace(code))
            Redirect(_nexaasId.GetAuthorizeUrl());

        ///Retrive user access token
        BaseResponse<OauthTokenResponse> authTokenResponse = await _nexaasId.GetAuthorizationToken(code);

        ///Retrive user data
        BaseResponse<Profile> profileResponse = await _nexaasId.GetProfile(authTokenResponse.Data);

        Profile profile = profileResponse.Data;

        ///Define user claims
        var claims = new []
        {
            new Claim(ClaimTypes.Name, profile.FullName),
            new Claim(ClaimTypes.Email, profile.Email),
            new Claim("NexaasIDAccessToken", authTokenResponse.Data.AccessToken), 
        };

        var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);

        ///Authenticates user
        await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, 
            new ClaimsPrincipal(claimsIdentity));

        return Redirect("~/");
    }

    [HttpGet]
    public async Task<IActionResult> Signout()
    {
        await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
        return Redirect("~/");
    }
}

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.8 2,085 4/15/2019
1.0.7 695 1/8/2019
1.0.6 663 10/18/2018
1.0.5 645 10/17/2018
1.0.4 671 10/17/2018
1.0.3 658 10/17/2018
1.0.0 637 10/16/2018