Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net identity 如何在asp.net核心web api中实现otp授权?_Asp.net Identity_Asp.net Core 2.0_Asp.net Core Webapi - Fatal编程技术网

Asp.net identity 如何在asp.net核心web api中实现otp授权?

Asp.net identity 如何在asp.net核心web api中实现otp授权?,asp.net-identity,asp.net-core-2.0,asp.net-core-webapi,Asp.net Identity,Asp.net Core 2.0,Asp.net Core Webapi,我想授权我的asp.net core web api的用户仅使用具有asp.NetCore标识的手机号码。当他们尝试使用电话号码登录时,otp将发送到该号码。如果他们提供正确的otp,则将生成令牌。我想使用我自己的短信api发送短信 这是我的令牌生成代码。 此方法在SignIn之后调用 private string GenerateAuthToken(ApplicationUser user) { var claims = new List<Clai

我想授权我的asp.net core web api的用户仅使用具有asp.NetCore标识的手机号码。当他们尝试使用电话号码登录时,otp将发送到该号码。如果他们提供正确的otp,则将生成令牌。我想使用我自己的短信api发送短信

这是我的令牌生成代码。 此方法在SignIn之后调用

private string GenerateAuthToken(ApplicationUser user)
        {
            var claims = new List<Claim>
            {
                new Claim(JwtRegisteredClaimNames.Sub, user.UserName),
                new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
                new Claim(ClaimTypes.NameIdentifier, user.Id)
            };

            var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration["JwtKey"]));
            var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
            var expires = Utilities.StaticProperties.GetCurrentDateTime().AddDays(Convert.ToDouble(_configuration["JwtExpireDays"]));

            var token = new JwtSecurityToken(
                _configuration["JwtIssuer"],
                _configuration["JwtIssuer"],
                claims,
                expires: expires,
                signingCredentials: creds);

            var tokenString = new JwtSecurityTokenHandler().WriteToken(token);
            return tokenString;
        }
private string GenerateAuthToken(ApplicationUser用户)
{
var索赔=新列表
{
新声明(JwtRegisteredClaimNames.Sub,user.UserName),
新声明(JwtRegisteredClaimNames.Jti,Guid.NewGuid().ToString()),
新声明(ClaimTypes.NameIdentifier,user.Id)
};
var key=new-SymmetricSecurityKey(Encoding.UTF8.GetBytes(_-configuration[“JwtKey”]);
var creds=新的签名凭证(key,SecurityAlgorithms.HmacSha256);
var expires=Utilities.StaticProperties.GetCurrentDateTime().AddDays(Convert.ToDouble(_配置[“JwtExpireDays]”));
var token=新的JwtSecurityToken(
_配置[“JwtIssuer”],
_配置[“JwtIssuer”],
声称,
过期:过期,
签署证书:信誉);
var tokenString=new JwtSecurityTokenHandler().WriteToken(令牌);
返回令牌字符串;
}

您的问题是什么?问题是我如何实现该功能。您在发送短信或检查短信方面有任何问题吗?两者,我如何发送和检查短信。您的问题是什么?问题是我如何实现该功能。您在发送短信或检查短信方面有任何问题吗?两者,我如何发送和检查短信。