예제 #1
0
        private String OnLogin(OAuthClient client, String state, String returnUrl)
        {
            var prov     = Provider;
            var redirect = prov.GetRedirect(Request, "~/Sso/LoginInfo/" + client.Name);
            // 请求来源,前后端分离时传front-end,重定向会带上token放到锚点
            var source = GetRequest("source");
            //if (state.IsNullOrEmpty() && !returnUrl.IsNullOrEmpty()) state = $"r={returnUrl}";
            //if (!source.IsNullOrEmpty())
            //{
            //    state += (state.IsNullOrEmpty() ? "" : "&") + $"s={source}";
            //}
            //state = HttpUtility.UrlEncode(state);

            var log = new OAuthLog
            {
                Provider     = client.Name,
                Action       = "Login",
                Success      = false,
                ResponseType = client.ResponseType,
                Scope        = client.Scope,
                State        = state,
                RedirectUri  = returnUrl,
                Source       = source
            };

            log.Insert();

            return(client.Authorize(redirect, log.Id + ""));
        }
예제 #2
0
        /// <summary>绑定</summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public virtual ActionResult Bind(String id)
        {
            var prov = Provider;

            var user = prov.Current;

            if (user == null)
            {
#if __CORE__
                var returnUrl = Request.GetEncodedPathAndQuery();
#else
                var returnUrl = Request.Url?.PathAndQuery;
#endif
                var rurl = "~/Admin/User/Login".AppendReturn(returnUrl);
                return(Redirect(rurl));
            }

            var url    = prov.GetReturnUrl(Request, true);
            var client = prov.GetClient(id);
            client.Init(GetUserAgent());

            var redirect = prov.GetRedirect(Request, "~/Sso/LoginInfo/" + client.Name);

            var log = new OAuthLog
            {
                Provider     = client.Name,
                Action       = "Bind",
                Success      = false,
                ResponseType = client.ResponseType,
                Scope        = client.Scope,
                State        = null,
                RedirectUri  = url,
            };
            log.Insert();

            url = client.Authorize(redirect, log.Id + "");

            return(Redirect(url));
        }