Giter Club home page Giter Club logo

aspnetcoreidentityfido2mfa's Introduction

ASP.NET Core Identity with FIDO2 WebAuthn, MFA and Passwordless

.NET

Database

Add-Migration "init_identity_new" 
Update-Database

Blogs

ASP.NET Core Identity with FIDO2 WebAuthn MFA

Adding FIDO2 Passwordless authentication to an ASP.NET Core Identity App

History

  • 2024-05-02 Updated packages and build
  • 2024-01-07 .NET 8
  • 2023-11-10 Updated packages
  • 2023-08-18 Updated packages, revert to Fido2 3.0.1 => problems with beta version
  • 2023-06-20 Updated packages, Fido2 4.0.0-beta1
  • 2023-04-28 Updated packages
  • 2023-02-18 Updated packages, improved passwordless login
  • 2022-12-31 Updated to .NET 7, fix passwordless login
  • 2022-10-15 Updated nuget packages
  • 2022-07-31 Updated Fido2 nuget package to 3.0.0 and npm, nuget packages
  • 2022-06-29 Updated Fido2 nuget package to 3.0.0-beta6
  • 2022-06-12 Migrate to latest identity, bootstrap 5, updated packages, nullable, implicit usings
  • 2022-02-13 Updated packages
  • 2021-12-16 Updated to .NET 6
  • 2021-08-20 Update npm packages
  • 2021-04-03 Update npm packages
  • 2021-03-20 Update npm, nuget packages
  • 2021-01-10 Update .NET 5, code clean up
  • 2020-09-11 Added Anti-forgery protection, Updated Nuget packages, npm packages
  • 2020-08-28 Fix Bad URL register FIDO key, Updated Nuget packages, npm packages
  • 2020-05-06 Fix FIDO2 database model
  • 2020-05-05 Updated nuget packages, FIDO2 1.1.0
  • 2020-02-28 Updated nuget packages, add support for multiple keys per user
  • 2019-12-29 Update to .NET Core 3.1
  • 2019-10-18 Added example for FIDO2 passwordless
  • 2019-10-07 Updated to .NET Core 3.0
  • 2019-09-20 Updated to .NET Core 3.0 rc1
  • 2019-09-06 Updated to .NET Core 3.0 preview 9
  • 2019-08-13 Updated to .NET Core 3.0 preview 8

Links

aspnetcoreidentityfido2mfa's People

Contributors

damienbod avatar dependabot[bot] avatar vanillajonathan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aspnetcoreidentityfido2mfa's Issues

.net without active directory option

Is it possible to use .net implementation without using active directory.

We have a .net mvc app publicly available and would like to go passwordless login - using active directory is out of the question as Microsoft

GetTwoFactorAuthenticationUserAsync();

await _signInManager.GetTwoFactorAuthenticationUserAsync() always returns null in release version, while it does function in development mode. I do see a cookie named Identity.TwoFactorUserId being set after the first step of logging in.

My environment is .NET 5.0

ReturnUrl in passwordless.login.js

In passwordless.login.js, instead of setting window.location.href = "/index", I suggest to redirect to the ReturnUrl like so:

    let returnUrl = findGetParameter('ReturnUrl');
    if (!returnUrl) {
        returnUrl = getFolder();
    }
    window.location.href = returnUrl;

using these helper functions:

function findGetParameter(parameterName) {
    var result = null,
        tmp = [];
    location.search
        .substr(1)
        .split("&")
        .forEach(function (item) {
            tmp = item.split("=");
            if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]);
        });
    return result;
}

and

function getFolder() {
    var dir = "";
    try {
        dir = document.getElementById('BasePath').value;
    } catch (e) {
    }
    return dir;
}

combined with this line added to Login.cshtml:

<input type="hidden" id="BasePath" name="BasePath" value="@Url.Content("~")">

Update to FIDO2 3 beta when ready

Consider upstreaming parts of this to the ASP.NET Core project.

Particularly the FidoStoredCredential model and the changes to ApplicationDbContextModelSnapshot.cs.

userHandle null

In passwordless.login.js, in verifyAssertionWithServer, if assertedCredential.response.userHandle is null, still userHandle in data.response is set to "" by coerceToBase64Url(userHandle). Suggest to add check on userHandle.length like so:
userHandle: userHandle !== null && userHandle.length > 0 ? coerceToBase64Url(userHandle) : null,

Bad href

mfa.register.js

window.location.href = "/Identity/Account/Manage/GenerateRecoveryCodes";

cannot register fido key when webapp is hosted on internet, but project work fine on localhost

Hi Damien,
I have tried your nice project. I have changed one thing on the fido2mfa.cshtml :

the value is set with the authenticatd user email instead of his username.

The project runs fine on my local host (iss express of visual studio 2019) with the below app settings :
"Fido2": {
"ServerDomain": "localhost",
"ServerName": "WebAuth Fenix",
"Origin": "http://localhost:44398",
"TimestampDriftTolerance": 300000,
"MDSAccessKey": null
}
I can register my fido2 yubikey, log in with it and unregistered it.

But when the test app (.Net 5 with razor pages) is deployed on internet (hosted at somee.com), I cannot register my fido2 yubikey at fido2mfa.cshtml.
I have tried the below settings, but I still get the error :
FIDO2_REGISTRATION_ERROR, exception:TypeError: Cannot read property 'create' of undefined

"Fido2": {
  "ServerDomain": "sipffenix.somee.com",
  "ServerName": "WebAuth Fenix",
  "Origin": "http://sipffenix.somee.com",
  "TimestampDriftTolerance": 300000,
  "MDSAccessKey": null
}

I have looked at the files 'MfaFido2RegisterController.cs' and 'mfa.register.js'.... Everything seems OK. I have not found something related to : "property 'create' of undefined"

Any idea about this bug ?

returnUrl is not handled correctly in case of FIDO2 login

After login redirection is always done to the root page.

The reason is that in the LoginFido2Mfa page the ReturnUrl is not stored.

It can be fixed applying the BindProperty attribute (with GET) in the page model.

[BindProperty(SupportsGet=true)]
public bool RememberMe { get; set; }

[BindProperty(SupportsGet = true)]
public string ReturnUrl { get; set; }

Failed to read the 'publicKey' property from 'CredentialCreationOptions'

Hi damien, i am trying out the mfa implementation but i am facing this error on registration exception:TypeError: Failed to execute 'create' on 'CredentialsContainer': Failed to read the 'publicKey' property from 'CredentialCreationOptions': Failed to read the 'attestation' property from 'PublicKeyCredentialCreationOptions': The provided value '0' is not a valid enum value of type AttestationConveyancePreference. on mfa.register.js line 80

i noticed these codes on MfaFidoRegisterController var items = await _fido2Storage.GetCredentialsByUsername(identityUser.UserName); var existingKeys = new List<PublicKeyCredentialDescriptor>(); foreach (var publicKeyCredentialDescriptor in items) { existingKeys.Add(publicKeyCredentialDescriptor.Descriptor); }
does this have anything to do with the error above?

  • i am using a copy of an existing AspNetIdentity Database and added the FidoStoredCredential table

Exception handling in PwFido2SignInController.cs

Hi Damien, I propose to move the "throw new ArgumentException("Username was not registered");" a few lines up: instead of checking the existence of the user, check the existence of the identityUser, for when that is empty, the new FidoUser will throw an uncaught exception. Suggestion: if (identityUser == null) throw new ArgumentException("Username was not registered");

User creation failure handling

In PwFido2RegisterController.cs, when user creation fails for whatever reason (e.g. invalidUserName if it contains blank spaces), this goes unnoticed. This could be improved by returning null from CreateUser if !result.Succeeded, but then you still end up having created FIDO credentials. Ideally, this would all be one transaction that can be rolled back upon failure, but maybe changing the order can help, creating the user first and only afterwards make the new credentials.

MfaFido2SignInFidoController constructor

Hi Damien, the MfaFido2SignInFidoController constructor contains this statement twice: "_userManager = userManager;" while it is not even used at all.
And while we're at it, wouldn't it be logical to include the result of the await _signInManager.TwoFactorSignInAsync("FIDO2", string.Empty, false, false) in the return value of the MakeAssertion call, or is this covered by the exception handler?
Nico

Deployment in subfolder breaks calls to back-end

In passwordless.login.js and passwordless.register.js, calls to back-end like "/pwmakeAssertion" don't work if the application is deployed in a subfolder like "https://somehost.com/myapplication/".
I suggest to
a) add this line to Login.cshtml and Register.cshtml:
<input type="hidden" id="BasePath" name="BasePath" value="@Url.Content("~")">
and
b) add a helper function like

function getFolder() {
    var dir = "";
    try {
        dir = document.getElementById('BasePath').value;
    } catch (e) {
    }
    return dir;
}

and then call
fetch(getFolder() + "/pwmakeAssertion" ....

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.