Example #1
0
        public void Login(string authtype)
        {
            var properties = new AuthenticationProperties {
                RedirectUri = Url.Action("Index", "Home")
            };

            AuthenticationManager.Challenge(properties, authtype);
        }
        public ActionResult Authorize(AuthorizeViewModel model, bool isGrant)
        {
            if (Response.StatusCode != 200)
            {
                return(View("AuthorizeError"));
            }

            if (ModelState.IsValid)
            {
                var scopes = model.Scope.Split(',');

                if (isGrant)
                {
                    var ticket   = AuthenticationManager.AuthenticateAsync(User.Identity.AuthenticationType).Result;
                    var identity = ticket != null ? ticket.Identity : null;
                    if (identity == null)
                    {
                        return(View("AuthorizeError"));
                    }
                    var oauthIdentity = identity;
                    if (!identity.AuthenticationType.Equals(OAuthDefaults.AuthenticationType, StringComparison.Ordinal))
                    {
                        oauthIdentity = new ClaimsIdentity(identity.Claims, OAuthDefaults.AuthenticationType, identity.NameClaimType, identity.RoleClaimType);
                    }
                    foreach (var scope in scopes)
                    {
                        oauthIdentity.AddClaim(new Claim("urn:oauth:scope", scope, oauthIdentity.AuthenticationType));
                    }
                    AuthenticationManager.SignIn(identity);
                }
                else
                {
                    AuthenticationManager.SignOut();
                    AuthenticationManager.Challenge();
                    return(new HttpUnauthorizedResult());
                }
            }
            return(View());
        }
        public ActionResult Authorize(AuthorizeViewModel model)
        {
            if (Response.StatusCode != 200)
            {
                return(View("AuthorizeError"));
            }
            if (!ModelState.IsValid)
            {
                return(View("AuthorizeError"));
            }

            if (!User.Identity.IsAuthenticated)
            {
                AuthenticationManager.Challenge();
                return(new HttpUnauthorizedResult());
            }

            var scopes = model.Scope.Split(',');

            ViewBag.IdentityName = AuthenticationManager.User.Identity.Name;
            ViewBag.scopes       = scopes;
            return(View());
        }