Esempio n. 1
0
        /// <summary>
        /// 获取 access token
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task <MicroSoft_AccessToken_ResultEntity> AccessToken(MicroSoft_AccessToken_RequestEntity entity)
        {
            if (!LoginBase.IsValid(entity))
            {
                return(null);
            }

            var config = await _microsoftConfigProvider.GetConfigAsync();

            config.CheckNotNull(nameof(config));

            string pars = LoginBase.EntityToPars(entity);

            string result = HttpTo.Post(config.API_AccessToken, pars);

            var outmo = LoginBase.ResultOutput <MicroSoft_AccessToken_ResultEntity>(result);

            return(outmo);
        }
Esempio n. 2
0
        /// <summary>
        /// Step4:根据用户ID获取用户信息
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task <Weibo_UserShow_ResultEntity> UserShow(Weibo_UserShow_RequestEntity entity)
        {
            if (!LoginBase.IsValid(entity))
            {
                return(null);
            }

            var config = await _weibaoConfigProvider.GetConfigAsync();

            config.CheckNotNull(nameof(config));

            string pars   = LoginBase.EntityToPars(entity);
            string result = HttpTo.Get(config.API_UserShow + "?" + pars);

            var outmo = LoginBase.ResultOutput <Weibo_UserShow_ResultEntity>(result, new List <string> {
                "status"
            });

            return(outmo);
        }
Esempio n. 3
0
        /// <summary>
        /// Step3:获取用户OpenId
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task <QQ_OpenId_ResultEntity> OpenId(QQ_OpenId_RequestEntity entity)
        {
            if (!LoginBase.IsValid(entity))
            {
                return(null);
            }

            var config = await _qqConfigProvider.GetConfigAsync();

            config.CheckNotNull(nameof(config));

            string pars   = LoginBase.EntityToPars(entity);
            string result = HttpTo.Get(config.API_OpenID_PC + "?" + pars);

            result = result.Replace("callback( ", "").Replace(" );", "");

            var outmo = LoginBase.ResultOutput <QQ_OpenId_ResultEntity>(result);

            return(outmo);
        }
Esempio n. 4
0
        /// <summary>
        /// 获取 access token
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task <GitHub_AccessToken_ResultEntity> AccessToken(GitHub_AccessToken_RequestEntity entity)
        {
            if (!LoginBase.IsValid(entity))
            {
                return(null);
            }

            var config = await _githubConfigProvider.GetConfigAsync();

            config.CheckNotNull(nameof(config));

            string pars = LoginBase.EntityToPars(entity);

            var hwr = HttpTo.HWRequest(config.API_AccessToken, "POST", pars);

            hwr.Accept = "application/json";//application/xml
            string result = HttpTo.Url(hwr);

            var outmo = LoginBase.ResultOutput <GitHub_AccessToken_ResultEntity>(result);

            return(outmo);
        }
Esempio n. 5
0
        /// <summary>
        /// Step1:获取Authorization Code
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task <string> AuthorizationHref(QQ_Authorization_RequestEntity entity)
        {
            if (!LoginBase.IsValid(entity))
            {
                return(null);
            }

            var config = await _qqConfigProvider.GetConfigAsync();

            config.CheckNotNull(nameof(config));

            return(string.Concat(new string[] {
                config.API_Authorization_PC,
                "?client_id=",
                entity.client_id,
                "&response_type=",
                entity.response_type,
                "&state=",
                entity.state,
                "&redirect_uri=",
                entity.redirect_uri.ToEncode()
            }));
        }
Esempio n. 6
0
        /// <summary>
        /// 获取 用户信息
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task <MicroSoft_User_ResultEntity> User(MicroSoft_User_RequestEntity entity)
        {
            if (!LoginBase.IsValid(entity))
            {
                return(null);
            }

            var config = await _microsoftConfigProvider.GetConfigAsync();

            config.CheckNotNull(nameof(config));

            string pars = LoginBase.EntityToPars(entity);

            var hwr = HttpTo.HWRequest(config.API_User + "?" + pars);

            hwr.ContentType = null;
            string result = HttpTo.Url(hwr);
            var    outmo  = LoginBase.ResultOutput <MicroSoft_User_ResultEntity>(result, new List <string> {
                "emails"
            });

            return(outmo);
        }
Esempio n. 7
0
        /// <summary>
        /// 请求授权地址
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task <string> AuthorizeHref(GitHub_Authorize_RequestEntity entity)
        {
            if (!LoginBase.IsValid(entity))
            {
                return(null);
            }

            var config = await _githubConfigProvider.GetConfigAsync();

            config.CheckNotNull(nameof(config));

            return(string.Concat(new string[] {
                config.API_Authorize,
                "?client_id=",
                entity.client_id,
                "&scope=",
                entity.scope.ToEncode(),
                "&state=",
                entity.state,
                "&redirect_uri=",
                entity.redirect_uri.ToEncode()
            }));
        }
Esempio n. 8
0
        /// <summary>
        /// 获取 用户信息
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task <GitHub_User_ResultEntity> User(GitHub_User_RequestEntity entity)
        {
            if (!LoginBase.IsValid(entity))
            {
                return(null);
            }

            var config = await _githubConfigProvider.GetConfigAsync();

            config.CheckNotNull(nameof(config));

            string pars = LoginBase.EntityToPars(entity);

            var hwr = HttpTo.HWRequest(config.API_User + "?" + pars);

            hwr.UserAgent = entity.ApplicationName;
            string result = HttpTo.Url(hwr);

            var outmo = LoginBase.ResultOutput <GitHub_User_ResultEntity>(result, new List <string> {
                "plan"
            });

            return(outmo);
        }