Ejemplo n.º 1
0
        public ActionResult LoginSSO(string issuer)
        {
            var identity = SamlIdentityService.Get(issuer);

            if (identity == null)
            {
                return new ContentResult {
                           Content = string.Concat(@"SSO failed. \n Issuer ", issuer, " is invalid.")
                }
            }
            ;

            return(Redirect(string.Concat(identity.IssuerURL, SamlParam(identity.IssuerURL),
                                          Url.Encode(SamlService.GenerateRequest(identity, SamlService.GenerateId(), SamlService.IssueInstant())))));
        }
Ejemplo n.º 2
0
        public ActionResult Consume(string issuer)
        {
            var response = new XmlResponse(Request.Form[SamlResponse]);
            var identity = SamlIdentityService.Get(issuer);

            if (identity == null)
            {
                return new ContentResult {
                           Content = string.Concat(@"SSO failed. \n Issuer ", issuer, " is invalid.")
                }
            }
            ;

            if (SamlService.ResponseIsValid(response, identity))
            {
                var userId = response.GetSubject();

                if (userId == null)
                {
                    return(Redirect(identity.IssuerLogoutUrl));
                }

                var token = SamlService.SetSsoToken(userId);
                if (token == null)
                {
                    return new ContentResult {
                               Content = string.Concat(@"SSO failed. \n User ", userId, " is invalid.")
                    }
                }
                ;

                return(Redirect(string.Concat(identity.AuthenticatedRedirectUrl, "?SSOtoken=", token, "&SamlIssuer=", identity.Issuer)));
            }
            return(new ContentResult {
                Content = @"SSO failed. \n Certificate is invalid."
            });
        }