コード例 #1
0
        public IActionResult AssertionOptionsTest([FromBody] TEST_AssertionClientParams assertionClientParams)
        {
            var username = assertionClientParams.Username;
            // 1. Get user from DB
            var user = DemoStorage.GetUser(username);

            if (user == null)
            {
                return(NotFound("username was not registered"));
            }

            // 2. Get registered credentials from database
            var existingCredentials = DemoStorage.GetCredentialsByUser(user).Select(c => c.Descriptor).ToList();

            var uv = assertionClientParams.UserVerification;

            if (null != assertionClientParams.authenticatorSelection && null == assertionClientParams.UserVerification)
            {
                uv = assertionClientParams.authenticatorSelection.UserVerification;
            }
            // 3. Create options
            var options = _lib.GetAssertionOptions(
                existingCredentials,
                uv
                );

            // 4. Temporarily store options, session/in-memory cache/redis/db
            HttpContext.Session.SetString("fido2.assertionOptions", options.ToJson());

            // 5. Return options to client
            return(Json(options));
        }
コード例 #2
0
        public IActionResult AssertionOptionsTest([FromBody] TEST_AssertionClientParams assertionClientParams)
        {
            var username = assertionClientParams.Username;
            // 1. Get user from DB
            var user = DemoStorage.GetUser(username);

            if (user == null)
            {
                return(NotFound("username was not registered"));
            }

            // 2. Get registered credentials from database
            var existingCredentials = DemoStorage.GetCredentialsByUser(user).Select(c => c.Descriptor).ToList();

            var uv = assertionClientParams.UserVerification;

            if (null != assertionClientParams.authenticatorSelection)
            {
                uv = assertionClientParams.authenticatorSelection.UserVerification;
            }

            var exts = new AuthenticationExtensionsClientInputs
            {
                AppID = _origin,
                SimpleTransactionAuthorization  = "FIDO",
                GenericTransactionAuthorization = new TxAuthGenericArg
                {
                    ContentType = "text/plain",
                    Content     = new byte[] { 0x46, 0x49, 0x44, 0x4F }
                },
                UserVerificationIndex = true,
                Location = true,
                UserVerificationMethod = true
            };

            if (null != assertionClientParams.Extensions && null != assertionClientParams.Extensions.Example)
            {
                exts.Example = assertionClientParams.Extensions.Example;
            }

            // 3. Create options
            var options = _fido2.GetAssertionOptions(
                existingCredentials,
                uv,
                exts
                );

            // 4. Temporarily store options, session/in-memory cache/redis/db
            HttpContext.Session.SetString("fido2.assertionOptions", options.ToJson());
            HttpContext.Session.SetString("fido2.assertionOptions.origin", _origin);

            // 5. Return options to client
            return(Json(options));
        }