コード例 #1
0
ファイル: TokenAuthController.cs プロジェクト: yb12306/MCSoft
        public async Task <AuthenticateResultModel> AuthenticateLogin([FromBody] AuthenticateInput input)
        {
            var openId = string.Empty;

#if DEBUG
            openId = "testopenid";
#else
            Console.WriteLine(WxOpenAppId);
            var jsonResult = await SnsApi.JsCode2JsonAsync(WxOpenAppId, WxOpenAppSecret, input.Code);

            if (jsonResult.errcode == ReturnCode.请求成功)
            {
                openId = jsonResult.openid;
            }
#endif
            Console.WriteLine(openId);
            var dto = await _userAppService.Authorize(openId, input.HeadId);

            IdentityUser login = new IdentityUser
            {
                RememberMe = true,
                UserId     = dto.Id.ToString(),
                Name       = dto.NickName,
            };

            var accessToken =
                CreateAccessToken(CreateJwtClaims(login.CreateIdentity(JwtBearerDefaults.AuthenticationScheme)));

            return(new AuthenticateResultModel
            {
                AccessToken = accessToken,
                ExpireInSeconds = (int)TimeSpan.FromDays(30).TotalSeconds,
                UserId = dto.Id.ToString()
            });
        }
コード例 #2
0
ファイル: TokenAuthController.cs プロジェクト: yb12306/MCSoft
        [ApiExplorerSettings(IgnoreApi = true)] //忽略接口,不在文档中显示
        public async Task <AuthenticateResultModel> AuthenticateTest([FromBody] TeatAuthenticateInput input)
        {
            var dto = await _userAppService.Authorize(input.OpenId, input.HeadId);

            IdentityUser login = new IdentityUser
            {
                RememberMe = true,
                UserId     = dto.Id.ToString(),
                Name       = dto.NickName,
            };

            var accessToken =
                CreateAccessToken(CreateJwtClaims(login.CreateIdentity(JwtBearerDefaults.AuthenticationScheme)));

            return(new AuthenticateResultModel
            {
                AccessToken = accessToken,
                ExpireInSeconds = (int)TimeSpan.FromDays(30).TotalSeconds,
                UserId = dto.Id.ToString()
            });
        }