コード例 #1
0
        /// <inheritdoc />
        public ResultMo <string> GetOauthUrl(string redirectUrl, string state,
                                             AuthClientType type)
        {
            var url = _api.GetAuthorizeUrl(redirectUrl, state, type);

            return(new ResultMo <string>(url));
        }
コード例 #2
0
ファイル: WxOauthApi.cs プロジェクト: peizihui/OSS.SnsSdk
        /// <summary>
        /// 获取授权地址
        /// </summary>
        /// <param name="redirectUri">授权后重定向的回调链接地址</param>
        /// <param name="state"> 需要回传的值 </param>
        /// <param name="type">授权客户端类型,如果是pc,则生成的是微信页面二维码授权页</param>
        /// <returns>授权的地址【如果 ApiConfig.OperateMode==AppOperateMode.ByAgent 回调除了 code 和 state 参数,还会有appid 】</returns>
        public string GetAuthorizeUrl(string redirectUri, string state, AuthClientType type)
        {
            if (redirectUri.Contains("://"))
            {
                redirectUri = redirectUri.UrlEncode();
            }

            var authUrl = new StringBuilder("https://open.weixin.qq.com/connect/");


            if (type == AuthClientType.Web)
            {
                authUrl.Append("qrconnect?appid=").Append(ApiConfig.AppId)
                .Append("&redirect_uri=").Append(redirectUri)
                .Append("&response_type=code&scope=snsapi_login");
            }
            else
            {
                var scope = type == AuthClientType.InnerSilence ? "snsapi_base" : "snsapi_userinfo";

                authUrl.Append("oauth2/authorize?appid=").Append(ApiConfig.AppId)
                .Append("&redirect_uri=").Append(redirectUri)
                .Append("&response_type=code&scope=").Append(scope);
            }
            authUrl.Append("&state=").Append(state);

            if (ApiConfig.OperateMode == AppOperateMode.ByAgent)
            {
                authUrl.Append("&component_appid=").Append(ApiConfig.ByAppId);
            }

            authUrl.Append("#wechat_redirect");
            return(authUrl.ToString());
        }
コード例 #3
0
ファイル: WxOauthApi.cs プロジェクト: zhangrl/OSS.Social
 /// <summary>
 /// 获取授权地址
 /// </summary>
 /// <param name="redirectUri">授权后重定向的回调链接地址,请使用urlencode对链接进行处理</param>
 /// <param name="type">授权客户端类型,如果是pc,则生成的是微信页面二维码授权页</param>
 /// <returns></returns>
 public string GetAuthorizeUrl(string redirectUri, AuthClientType type)
 {
     if (type == AuthClientType.WxOffcial)
     {
         return
             ($"https://open.weixin.qq.com/connect/oauth2/authorize?appid={ApiConfig.AppId}&redirect_uri={redirectUri}&response_type=code&scope=snsapi_userinfo&state={ApiConfig.AppSource}#wechat_redirect");
     }
     return
         ($"https://open.weixin.qq.com/connect/qrconnect?appid={ApiConfig.AppId}&redirect_uri={redirectUri}&response_type=code&scope=snsapi_login&state={ApiConfig.AppSource}#wechat_redirect");
 }
コード例 #4
0
        public ResultMo <string> GetOauthUrl(ThirdPaltforms plat, string redirectUrl, string state, AuthClientType type)
        {
            var url = _OauthApi.GetAuthorizeUrl(redirectUrl, state, type);

            return(new ResultMo <string>(url));
        }
コード例 #5
0
ファイル: JwtToken.cs プロジェクト: 946061526/Test.Ocelot
        /// <summary>
        /// 获取基于JWT的Token
        /// </summary>
        /// <param name="claims"></param>
        /// <param name="permissionRequirement"></param>
        /// <param name="clientType"></param>
        /// <param name="TokenType">1.token   2 refreshToken</param>
        /// <returns></returns>
        public static dynamic BuildJwtToken(Claim[] claims, PermissionRequirement permissionRequirement, AuthClientType clientType)
        {
            double expiresIn             = 2 * 60 * 60 * 1000;
            double refreshTokenExpiresIn = 24 * 60 * 60 * 1000;

            switch (clientType)
            {
            case AuthClientType.Web:                        //SAAS后台
                refreshTokenExpiresIn = 8 * 60 * 60 * 1000; //设置成8小时
                break;

            case AuthClientType.Wehcat:                          //小程序
                refreshTokenExpiresIn = 7 * 24 * 60 * 60 * 1000; //设置成7天  用于小程序客户端之类的,能确保一周永久在线
                break;

            default:
                refreshTokenExpiresIn = 7 * 24 * 60 * 60 * 1000;
                break;
            }

            var now       = DateTime.Now;
            var jwt_token = new JwtSecurityToken(
                issuer: permissionRequirement.Issuer,
                audience: permissionRequirement.Audience,
                claims: claims,
                notBefore: now,
                expires: now.Add(TimeSpan.FromMilliseconds(expiresIn)),
                //expires: now.Add(TimeSpan.FromMilliseconds(5 * 60 * 1000)),
                signingCredentials: permissionRequirement.SigningCredentials
                );

            //用于refresh使用的 jwt
            var jwt_refreshtoken = new JwtSecurityToken(
                issuer: permissionRequirement.Issuer,
                audience: permissionRequirement.Audience,
                claims: claims,
                notBefore: now,
                expires: now.Add(TimeSpan.FromMilliseconds(refreshTokenExpiresIn)),
                //expires: now.Add(TimeSpan.FromMilliseconds(1000 * 60 * 10)),
                signingCredentials: permissionRequirement.SigningCredentials
                );

            var encodedJwt_Token        = new JwtSecurityTokenHandler().WriteToken(jwt_token);
            var encodedJwt_RefreshToken = new JwtSecurityTokenHandler().WriteToken(jwt_refreshtoken);

            var responseTokenJson = new
            {
                access_token = encodedJwt_Token,
                expires      = now.Add(TimeSpan.FromMilliseconds(expiresIn)),
                expires_in   = expiresIn,
                //expires = now.Add(TimeSpan.FromMilliseconds(5 * 60 * 1000)),
                //expires_in = 5 * 60 * 1000,
                token_type           = "Bearer",
                refresh_access_token = new
                {
                    refresh_token = encodedJwt_RefreshToken,
                    expires       = now.Add(TimeSpan.FromMilliseconds(refreshTokenExpiresIn)),
                    expires_in    = refreshTokenExpiresIn
                                    //expires = now.Add(TimeSpan.FromMilliseconds(1000 * 60 * 10)),
                                    //expires_in = 1000 * 60 * 10
                }
            };

            return(responseTokenJson);
        }
コード例 #6
0
 public ResultMo <string> GetOauthUrl(SocialPaltforms plat, string redirectUrl, string state, AuthClientType type)
 {
     return(service.GetOauthUrl(plat, redirectUrl, state, type));
 }
コード例 #7
0
 /// <summary>
 /// 获取授权地址
 /// </summary>
 /// <param name="redirectUrl"></param>
 /// <param name="state"></param>
 /// <param name="type"></param>
 /// <returns></returns>
 public virtual ResultMo <string> GetOauthUrl(string redirectUrl, string state,
                                              AuthClientType type)
 {
     return(new ResultMo <string>(ResultTypes.UnKnowSource, "未知应用平台!"));
 }
コード例 #8
0
ファイル: OauthService.cs プロジェクト: zouxinghan/OSS.Core
        /// <summary>
        /// 获取授权地址
        /// </summary>
        /// <param name="plat">平台</param>
        /// <param name="redirectUrl">重定向回跳地址</param>
        /// <param name="state">返回参数,自行编码</param>
        /// <param name="type">授权类型</param>
        /// <returns></returns>

        public ResultMo <string> GetOauthUrl(SocialPaltforms plat, string redirectUrl, string state, AuthClientType type)
        {
            var handler = SnsCommon.GetHandlerByPlatform(plat);

            return(handler.GetOauthUrl(redirectUrl, state, type));
        }