Пример #1
0
        public ActionResult AutoExternalLoginIn(string clientId, string targetUrl)
        {
            var token = _authService.GenerateToken(clientId, User.Identity.Name);
            Uri url;

            if (string.IsNullOrEmpty(token) || string.IsNullOrEmpty(targetUrl) || !Uri.TryCreate(targetUrl, UriKind.Absolute, out url))
            {
                var strMsg = string.Format("get token faild for {0}!", User.Identity.Name);

                return(View("~/Views/Shared/Error.cshtml", new HandleErrorInfo(new Exception(strMsg), "OAuth", "AutoExternalLoginIn")));
            }

            //from one level cache
            //var client = _clientDataService.Repository.Entities.First(x => x.ClientId == clientId);//_authService.TokenContext.OAuthClient.ClientCallBackUrl;



            var builder = new UriBuilder(url);

            var query = HttpUtility.ParseQueryString(builder.Query);

            query.Add("token", token);
            //query.Add("redirectUrl", targetUrl);

            builder.Query = query.ToString();

            return(Redirect(builder.ToString()));
        }
Пример #2
0
        public JsonResult Token([FromForm] TokenModel model, [FromHeader(Name = "Authorization")] string authorization)
        {
            var result = _authorizeService.GenerateToken(new AskTokenDto()
            {
                AuthorizationHeader = authorization,
                ClientPublicId      = model.ClientId,
                CodeValue           = model.Code,
                GrantType           = model.GrantType,
                Password            = model.Password,
                RedirectUrl         = model.RedirectUrl,
                RefreshToken        = model.RefreshToken,
                Scope             = model.Scope,
                ParameterUsername = model.Username
            });

            if (!String.IsNullOrWhiteSpace(result.RefreshToken))
            {
                return(new JsonResult(new
                {
                    access_token = result.AccessToken,
                    token_type = result.TokenType,
                    expires_in = result.ExpireIn,
                    refresh_token = result.RefreshToken,
                    scope = result.Scope
                }));
            }
            else
            {
                return(new JsonResult(new
                {
                    access_token = result.AccessToken,
                    token_type = result.TokenType,
                    expires_in = result.ExpireIn,
                    scope = result.Scope
                }));
            }
        }