Skip to content

Commit

Permalink
Prep for V9 (#449)
Browse files Browse the repository at this point in the history
* Update packages

* #404 - remove callinitiatior from CollectResponse. Not returned from api and not referenced in to this in bankId docs.

* Update version number to 9.0 rc-1

* #404 - add a sample of how the phone auth/sign work

* FIxes

---------

Co-authored-by: Marcus Abrahamsson <marcus.abrahamsson13@gmail.com>
  • Loading branch information
PeterOrneholm and Abrissirba committed Apr 18, 2024
1 parent 3446866 commit aade18f
Show file tree
Hide file tree
Showing 24 changed files with 394 additions and 89 deletions.
7 changes: 7 additions & 0 deletions ActiveLogin.Authentication.sln
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".devcontainer", ".devcontai
.devcontainer\Dockerfile = .devcontainer\Dockerfile
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Phone.ConsoleSample", "samples\Phone.ConsoleSample\Phone.ConsoleSample.csproj", "{A77ECBA8-5F9F-4C60-A4D0-08CAC023E4BE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -181,6 +183,10 @@ Global
{D3673E53-A774-46F0-9E44-97DF8F52D6D8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D3673E53-A774-46F0-9E44-97DF8F52D6D8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D3673E53-A774-46F0-9E44-97DF8F52D6D8}.Release|Any CPU.Build.0 = Release|Any CPU
{A77ECBA8-5F9F-4C60-A4D0-08CAC023E4BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A77ECBA8-5F9F-4C60-A4D0-08CAC023E4BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A77ECBA8-5F9F-4C60-A4D0-08CAC023E4BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A77ECBA8-5F9F-4C60-A4D0-08CAC023E4BE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -207,6 +213,7 @@ Global
{A66B2FFF-0CB6-4F48-83DA-6C1F7DC98EBF} = {4764448D-A014-403F-A956-3F4CFFA00AF2}
{61360399-F211-4B18-88EE-2A6F4D2C1FE6} = {9A0CF459-87CC-448D-B49D-EFC3D6482AA6}
{D3673E53-A774-46F0-9E44-97DF8F52D6D8} = {12A0FDF2-523E-42C7-81FE-4FDCA5E66A69}
{A77ECBA8-5F9F-4C60-A4D0-08CAC023E4BE} = {8E4C5EA1-1B2E-4B78-9F44-6BC85E42A752}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2076F58C-968B-489D-94CA-B3729F5DE10D}
Expand Down
43 changes: 24 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,29 @@ _Screenshot on monitoring dashboard._

___Note:___ This Readme reflects the state of our main branch and the code documented here might not be released as packages on NuGet.org yet. For early access, see our [CI builds](#projects--packages-overview).

* [Features](#features)
* [Screenshots](#screenshots)
* [Projects & Packages overview](#projects--packages-overview)
* [Usage & Docs](#usage--docs)
* [Samples](#samples)
* [Tests](#tests)
* [FAQ](#faq)
+ [What version of .NET is supported?](#what-version-of-net-is-supported)
+ [How do I build the solution locally?](#how-do-i-build-the-solution-locally)
+ [How do I run the samples locally?](#how-do-i-run-the-samples-locally)
+ [How do I use Active Login to get support for BankID in Azure AD (Active Directory) B2C?](#how-do-i-use-active-login-to-get-support-for-bankid-in-azure-ad-active-directory-b2c)
* [Active Login](#active-login)
+ [Security](#security)
+ [Contribute](#contribute)
+ [Stay updated and join the discussion](#stay-updated-and-join-the-discussion)
+ [License](#license)
+ [Acknowledgements](#acknowledgements)
+ [Sponsors](#sponsors)
+ [Support & Training](#support--training)
- [ActiveLogin.Authentication](#activeloginauthentication)
- [Features](#features)
- [Screenshots](#screenshots)
- [Table of contents](#table-of-contents)
- [Projects \& Packages overview](#projects--packages-overview)
- [Usage \& Docs](#usage--docs)
- [Samples](#samples)
- [Tests](#tests)
- [FAQ](#faq)
- [What version of .NET is supported?](#what-version-of-net-is-supported)
- [How do I build the solution locally?](#how-do-i-build-the-solution-locally)
- [Devcontainer and GitHub Codespaces](#devcontainer-and-github-codespaces)
- [How do I run the samples locally?](#how-do-i-run-the-samples-locally)
- [How do I use Active Login to get support for BankID in Azure AD (Active Directory) B2C?](#how-do-i-use-active-login-to-get-support-for-bankid-in-azure-ad-active-directory-b2c)
- [Active Login](#active-login)
- [Security](#security)
- [Contribute](#contribute)
- [Contributors](#contributors)
- [Stay updated and join the discussion](#stay-updated-and-join-the-discussion)
- [License](#license)
- [Acknowledgements](#acknowledgements)
- [Sponsors](#sponsors)
- [Support \& Training](#support--training)


## Projects & Packages overview
Expand Down Expand Up @@ -130,6 +134,7 @@ _Note: These are samples on how to use Active Login in different situations and
| [IdentityServer.ServerSample](https://github.com/ActiveLogin/ActiveLogin.Authentication/tree/main/samples/IdentityServer.ServerSample) | IdentityServer with Active Login as auth provider for BankID. |
| [Standalone.MvcSample](https://github.com/ActiveLogin/ActiveLogin.Authentication/tree/main/samples/Standalone.MvcSample) | ASP.NET MVC with Active Login as auth provider for BankID. Also demo of Sign. |
| [AzureProvisioningSample](https://github.com/ActiveLogin/ActiveLogin.Authentication/tree/main/samples/AzureProvisioningSample) | ARM template with Azure KeyVault, Azure App Service, Azure Monitor / Application Insights etc. |
| [Phone.ConsoleSample](https://github.com/ActiveLogin/ActiveLogin.Authentication/tree/main/samples/Phone.ConsoleSample) | Console application with a simple Phone Auth/Sign example |

_Please note that IdentityServer.ClientSample uses IdentityServer.ServerSample as the IdentityProvider, so the IdentityServer.ClientSample is a good place to start._

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="8.0.4" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.22.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Duende.IdentityServer" Version="6.3.7" />
<PackageReference Include="Duende.IdentityServer" Version="7.0.4" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.22.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="8.0.4" />
<PackageReference Include="Microsoft.Extensions.Logging.ApplicationInsights" Version="2.22.0" />
</ItemGroup>

Expand Down
168 changes: 168 additions & 0 deletions samples/Phone.ConsoleSample/BankIdDemoHostedService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
using ActiveLogin.Authentication.BankId.Api;
using ActiveLogin.Authentication.BankId.Api.Models;
using ActiveLogin.Identity.Swedish;

using Microsoft.Extensions.Hosting;

namespace Phone.ConsoleSample;

//
// DISCLAIMER - DO NOT USE FOR REAL
//
// This is samples to show how the BankID phone flow works.
// You can't use BankID in this way in an application for real
// as the client certificates would be exposed.
//
// Please see this as technical demo of how the flow works,
// not something to use. In a production scenario you should
// integrate this into a backoffice system.
//

internal sealed class BankIdDemoHostedService : IHostedService
{
private readonly IBankIdAppApiClient _bankIdApiClient;
private readonly IHostApplicationLifetime _appLifetime;

public BankIdDemoHostedService(
IBankIdAppApiClient bankIdApiClient,
IHostApplicationLifetime appLifetime
)
{
_bankIdApiClient = bankIdApiClient;
_appLifetime = appLifetime;
}

public async Task StartAsync(CancellationToken cancellationToken)
{
await RunBankIdFlowAsync();
_appLifetime.StopApplication();

}

public Task StopAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;
}

public async Task RunBankIdFlowAsync()
{
var personalIdentityNumber = GetPersonalIdentityNumber();
var sessionType = GetSessionType();
var callInitiatior = GetCallInitiator();

var orderRef = await InitiateAsync(personalIdentityNumber, sessionType, callInitiatior);
await CollectAsync(orderRef);
}

private string GetPersonalIdentityNumber()
{
ConsoleHelper.WriteHeader("Enter the personal identity number (YYYYMMDDXXXX) of the one:");
while (true)
{
var personalIdentityNumber = Console.ReadLine();

if (!string.IsNullOrEmpty(personalIdentityNumber))
{
var success = PersonalIdentityNumber.TryParse(personalIdentityNumber, out var parsedPersonalIdentityNumber);
if (success)
{
Console.WriteLine();
return parsedPersonalIdentityNumber.To12DigitString();
}
else
{
Console.WriteLine("Invalid personal identity number. Please try again.");
}
}
else
{
Console.WriteLine("Input cannot be empty. Please try again.");
}
}
}

private SessionType GetSessionType()
{
ConsoleHelper.WriteHeader("Do you want to test an auth or sign session?");
var sessionType = ConsoleHelper.DisplayMenuAndGetSelectedKey(new List<(string Key, string DisplayName)>
{
(SessionType.Auth.ToString(), "Auth"),
(SessionType.Sign.ToString(), "Sign")
});
return Enum.Parse<SessionType>(sessionType);
}

private CallInitiator GetCallInitiator()
{
ConsoleHelper.WriteHeader("Who is the initiator of the session?");
var callInitiatior = ConsoleHelper.DisplayMenuAndGetSelectedKey(new List<(string Key, string DisplayName)>
{
(CallInitiator.RP.ToString(), $"{CallInitiator.RP} - user called the RP"),
(CallInitiator.User.ToString(), $"{CallInitiator.User} - RP called the user")
});
return Enum.Parse<CallInitiator>(callInitiatior);
}

private async Task<string> InitiateAsync(string personalIdentityNumber, SessionType sessionType, CallInitiator callInitiator)
{
ConsoleHelper.WriteHeader($"Initiates a {sessionType} session");
var orderRef = "";
if (sessionType == SessionType.Auth)
{
var response = await _bankIdApiClient.PhoneAuthAsync(new PhoneAuthRequest(
personalIdentityNumber: personalIdentityNumber,
callInitiator: callInitiator,
requirement: null,
userVisibleData: null,
userNonVisibleData: null,
userVisibleDataFormat: null
));
orderRef = response.OrderRef;
}
else
{
var response = await _bankIdApiClient.PhoneSignAsync(new PhoneSignRequest(
personalIdentityNumber: personalIdentityNumber,
callInitiator: callInitiator,
requirement: null,
userVisibleData: "Hello, this is just a sample",
userNonVisibleData: null,
userVisibleDataFormat: null
));
orderRef = response.OrderRef;
}
Console.WriteLine($"Successfully initiated a session with orderRef: {orderRef}");
Console.WriteLine();
return orderRef;
}

private async Task CollectAsync(string orderRef)
{
ConsoleHelper.WriteHeader($"Collecte status for orderRef: {orderRef}");
while (true)
{
var collectResponse = await _bankIdApiClient.CollectAsync(new CollectRequest(orderRef));
var status = collectResponse.GetCollectStatus();
if (status == CollectStatus.Pending)
{
Console.WriteLine($"Pending. HintCode: {collectResponse.HintCode}");
await Task.Delay(2000);
}
else if (status == CollectStatus.Complete)
{
Console.WriteLine("");
ConsoleHelper.WriteHeader("Collect completed");
Console.WriteLine($"Name: {collectResponse.CompletionData!.User.Name}");
Console.WriteLine($"Ip-Adress: {collectResponse.CompletionData!.Device.IpAddress}");
break;
}
else
{
Console.WriteLine("");
ConsoleHelper.WriteHeader($"Failed. HintCode: {collectResponse.HintCode}");
break;
}
}
}

}
54 changes: 54 additions & 0 deletions samples/Phone.ConsoleSample/ConsoleHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Phone.ConsoleSample;
public static class ConsoleHelper
{
public static void WriteHeader(string text)
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(text);
Console.ResetColor();
}

public static string DisplayMenuAndGetSelectedKey(List<(string Key, string DisplayName)> menuItems)
{
int currentIndex = 0;
ConsoleKeyInfo keyInfo;
int menuStartRow = Console.CursorTop;

do
{
for (int i = 0; i < menuItems.Count; i++)
{
Console.SetCursorPosition(0, menuStartRow + i);

if (i == currentIndex)
{
Console.BackgroundColor = ConsoleColor.Gray;
Console.ForegroundColor = ConsoleColor.Black;
}

Console.WriteLine("* " + menuItems[i].DisplayName.PadRight(Console.WindowWidth - 1));
Console.ResetColor();
}

keyInfo = Console.ReadKey(true);

if (keyInfo.Key == ConsoleKey.UpArrow)
{
currentIndex = (currentIndex - 1 + menuItems.Count) % menuItems.Count;
}
else if (keyInfo.Key == ConsoleKey.DownArrow)
{
currentIndex = (currentIndex + 1) % menuItems.Count;
}

} while (keyInfo.Key != ConsoleKey.Enter);

return menuItems[currentIndex].Key;
}
}
34 changes: 34 additions & 0 deletions samples/Phone.ConsoleSample/Phone.ConsoleSample.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>

<Product>Active Login</Product>
<Description>ASP.NET sample for Active Login.</Description>
<Authors>Active Solution</Authors>
<Company>Active Solution</Company>
<Copyright>Copyright © 2018-2024 Active Solution</Copyright>

<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

<OutputType>Exe</OutputType>

<UserSecretsId>b910e9a7-c8bc-4350-8de2-e5b4c57753ed</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\ActiveLogin.Authentication.BankId.Api\ActiveLogin.Authentication.BankId.Api.csproj" />
<ProjectReference Include="..\..\src\ActiveLogin.Authentication.BankId.AzureKeyVault\ActiveLogin.Authentication.BankId.AzureKeyVault.csproj" />
<ProjectReference Include="..\..\src\ActiveLogin.Authentication.BankId.Core\ActiveLogin.Authentication.BankId.Core.csproj" />
</ItemGroup>

</Project>
Loading

0 comments on commit aade18f

Please sign in to comment.