/// <summary>
 /// 配置刷新令牌
 /// </summary>
 /// <param name="builder">授权参数生成器</param>
 /// <param name="token">访问令牌参数</param>
 /// <param name="config">授权配置</param>
 protected override void ConfigRefreshToken(AuthorizationParameterBuilder builder, string token, WechatAuthorizationConfig config)
 {
     builder.GatewayUrl(config.RefreshTokenUrl)
     .AppId(config.AppId)
     .GrantType(OAuthConst.RefreshToken)
     .RefreshToken(token);
 }
 /// <summary>
 /// 配置
 /// </summary>
 /// <param name="builder">授权参数生成器</param>
 /// <param name="param">授权参数</param>
 /// <param name="config">授权配置</param>
 protected override void ConfigGenerateUrl(AuthorizationParameterBuilder builder, AuthorizationParam param, OsChinaAuthorizationConfig config)
 {
     builder.GatewayUrl(PcAuthorizationUrl)
     .ClientId(config.AppId)
     .ResponseType(param.ResponseType)
     .RedirectUri(string.IsNullOrWhiteSpace(param.RedirectUri) ? config.CallbackUrl : param.RedirectUri)
     .State(param.State);
 }
 /// <summary>
 /// 配置获取访问令牌
 /// </summary>
 /// <param name="builder">授权参数生成器</param>
 /// <param name="param">访问令牌参数</param>
 /// <param name="config">授权配置</param>
 protected override void ConfigGetToken(AuthorizationParameterBuilder builder, AccessTokenParam param, WechatAuthorizationConfig config)
 {
     builder.GatewayUrl(config.AccessTokenUrl)
     .AppId(config.AppId)
     .Secret(config.AppKey)
     .Code(param.Code)
     .GrantType(OAuthConst.AuthorizationCode);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 配置
 /// </summary>
 /// <param name="builder">授权参数生成器</param>
 /// <param name="param">授权参数</param>
 /// <param name="config">授权配置</param>
 protected override void ConfigGenerateUrl(AuthorizationParameterBuilder builder, AuthorizationParam param, GithubAuthorizationConfig config)
 {
     builder.GatewayUrl(config.AuthorizationUrl)
     .ClientId(config.AppId)
     .Scope(param.Scope)
     .State(param.State)
     .RedirectUri(string.IsNullOrWhiteSpace(param.RedirectUri) ? config.CallbackUrl : param.RedirectUri)
     .Add("allow_signup", param.AllowSignup ? "true" : "false");
 }
 /// <summary>
 /// 配置获取访问令牌
 /// </summary>
 /// <param name="builder">授权参数生成器</param>
 /// <param name="param">访问令牌参数</param>
 /// <param name="config">授权配置</param>
 protected override void ConfigGetToken(AuthorizationParameterBuilder builder, AccessTokenParam param, GiteeAuthorizationConfig config)
 {
     builder.GatewayUrl(config.AccessTokenUrl)
     .GrantType(OAuthConst.AuthorizationCode)
     .Code(param.Code)
     .ClientId(config.AppId)
     .RedirectUri(string.IsNullOrWhiteSpace(param.RedirectUri) ? config.CallbackUrl : param.RedirectUri,
                  false)
     .ClientSecret(config.AppKey);
 }
        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="param">授权用户参数</param>
        /// <returns></returns>
        public async Task<GithubAuthorizationUserInfoResult> GetUserInfoAsync(GithubAuthorizationUserRequest param)
        {
            var config = await ConfigProvider.GetConfigAsync();
            Validate(config, param.ToParam());
            var builder = new AuthorizationParameterBuilder();
            builder.GatewayUrl(GetUserInfoUrl)
                .AccessToken(param.AccessToken);

            var result = await RequestResult(config, builder, ParameterParserType.Json,
                (t) => t.HasKey("id"));
            return result.Success ? result.Result.ToObject<GithubAuthorizationUserInfoResult>() : null;
        }
Ejemplo n.º 7
0
 /// <summary>
 /// 配置
 /// </summary>
 /// <param name="builder">授权参数生成器</param>
 /// <param name="param">授权参数</param>
 /// <param name="config">授权配置</param>
 protected override void ConfigGenerateUrl(AuthorizationParameterBuilder builder, AuthorizationParam param, WeiboAuthorizationConfig config)
 {
     builder.GatewayUrl(config.AuthorizationUrl)
     .ClientId(config.AppId)
     .ResponseType(param.ResponseType)
     .State(param.State)
     .RedirectUri(string.IsNullOrWhiteSpace(param.RedirectUri) ? config.CallbackUrl : param.RedirectUri)
     .Scope(param.Scope)
     .Add("display", param.Display)
     .Add("forcelogin", param.Forcelogin.ToString().ToLower())
     .Add("language", param.Language);
 }
Ejemplo n.º 8
0
        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="param">授权用户参数</param>
        /// <returns></returns>
        public async Task <CodingAuthorizationUserInfoResult> GetUserInfoAsync(CodingAuthorizationUserRequest param)
        {
            var config = await ConfigProvider.GetConfigAsync();

            Validate(config, param.ToParam());
            var builder = new AuthorizationParameterBuilder();

            builder.GatewayUrl(GetUserInfoUrl)
            .AccessToken(param.AccessToken);

            var result = await RequestResult(config, builder, ParameterParserType.Json,
                                             (t) => t.GetValue("code") == "0");

            return(result.Success ? result.GetValue("data").ToObject <CodingAuthorizationUserInfoResult>() : null);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="param">授权用户参数</param>
        /// <returns></returns>
        public async Task <QQAuthorizationUserInfoResult> GetUserInfoAsync(QQAuthorizationUserRequest param)
        {
            var config = await ConfigProvider.GetConfigAsync();

            Validate(config, param.ToParam());
            var builder = new AuthorizationParameterBuilder();

            builder.GatewayUrl(GetUserInfoUrl)
            .AccessToken(param.AccessToken)
            .Add("oauth_consumer_key", config.AppId)
            .OpenId(param.OpenId);
            var result = await RequestResult(config, builder, ParameterParserType.Json,
                                             (t) => t.GetValue("ret") == "0");

            return(result.Success ? result.Result.ToObject <QQAuthorizationUserInfoResult>() : null);
        }
        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="param">授权用户参数</param>
        /// <returns></returns>
        public async Task <WechatAuthorizationUserInfoResult> GetUserInfoAsync(WechatAuthorizationUserRequest param)
        {
            var config = await ConfigProvider.GetConfigAsync();

            Validate(config, param.ToParam());
            var builder = new AuthorizationParameterBuilder();

            builder.GatewayUrl(GetUserInfoUrl)
            .AccessToken(param.AccessToken)
            .OpenId(param.OpenId)
            .Add("lang", param.Lang);

            var result = await RequestResult(config, builder, ParameterParserType.Json,
                                             (t) => t.HasKey("openid"));

            return(result.Success ? result.Result.ToObject <WechatAuthorizationUserInfoResult>() : null);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 获取用户OpenId
        /// </summary>
        /// <param name="token">授权令牌</param>
        /// <returns></returns>
        public async Task <string> GetOpenIdAsync(string token)
        {
            if (string.IsNullOrWhiteSpace(token))
            {
                throw new ArgumentNullException(nameof(token));
            }
            var config = await ConfigProvider.GetConfigAsync();

            Validate(config);
            var builder = new AuthorizationParameterBuilder();

            builder.GatewayUrl(GetOpenIdUrl)
            .AccessToken(token);
            var result = await RequestResult(config, builder, ParameterParserType.Jsonp, (t) => t.HasKey("openid"));

            if (!config.AppId.Equals(result.GetValue(OAuthConst.ClientId)))
            {
                throw new ArgumentException("客户端ID不一致");
            }
            return(result.GetValue("openid"));
        }