Esempio n. 1
0
        /// <summary>
        /// 处理密码授权
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        private OAuthBaseModel PasswordGrant(string userName, string password)
        {
            if (string.IsNullOrEmpty(userName) || password != userService.FindUserPassword(userName))
            {
                WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.Unauthorized;
                return(new OAuthError("invalid_user", "user is invalid"));
            }
            var oauthEntity = tokenService.FindOAuthEntityByUsername(userName);

            if (oauthEntity == null)
            {
                oauthEntity = CreateOAuthEntity(userName, password);
                SaveToStore(oauthEntity);
            }
            return(oauthEntity);
        }