コード例 #1
0
        public async Task <JsonResult> RequstToken(AuthenticationInputModel input)
        {
            //TODO 更新登录IP跟时间
            // discover endpoints from metadata
            var client = new HttpClient();
            var disco  = await client.GetDiscoveryDocumentAsync("http://localhost:5000");

            if (disco.IsError)
            {
                return(Json(disco.Error));
            }

            // request token
            var tokenResponse = await client.RequestPasswordTokenAsync(new PasswordTokenRequest
            {
                Address      = disco.TokenEndpoint,
                UserName     = input.UserName,                         //"admin",
                Password     = MD5Encrypt.EncryptBy32(input.Password), // "95ec2e295d99fa60fbb1e245175a25",
                ClientId     = "client2",
                ClientSecret = "secret",
            });

            AuthenticationOutputMessageModel model = new AuthenticationOutputMessageModel();

            if (tokenResponse.IsError)
            {
                model.Code    = 50008;
                model.Message = tokenResponse.Error;
                return(Json(model));
            }
            model.Code = 20000;
            model.Data = tokenResponse;
            return(Json(model));
        }
コード例 #2
0
        public AuthenticationResultModel Authenticate(AuthenticationInputModel input)
        {
            var outputModel = new AuthenticationResultModel {
                Input = input
            };

            var operation = _authentications.FirstOrDefault(a => a.Metadata.AuthenticationType == input.TypeString);

            outputModel.Result = operation == null ? "Implementation cannot be found" : operation.Value.Authenticate(input.Username, input.Password);

            return(outputModel);
        }
コード例 #3
0
 public AuthenticationViewModel GetAuthenticationInfo(AuthenticationInputModel inputModel)
 {
     return(_userPresentationService.GetAuthenticationViewModel(inputModel));
 }