Exemplo n.º 1
0
        public object Get(Login request)
        {
            /*
             * // Create the authentication request.
             * XmlElement authnRequestXml = CreateAuthnRequest();
             *
             * // Create and cache the relay state so we remember which SP resource the user wishes to access after SSO.
             * string spResourceURL = "~/";
             * string relayState = RelayStateCache.Add(new RelayState(spResourceURL, null));
             *
             * // Send the authentication request to the identity provider over the configured binding.
             *
             * X509Certificate2 x509Certificate = new X509Certificate2(@"C:\Program Files (x86)\ComponentSpace SAML v2.0 for .NET\Examples\SSO\HighLevelAPI\MVC\MvcExampleServiceProvider\Certificates\MVCTest.cer");
             *
             *      ServiceProvider.SendAuthnRequestByHTTPRedirect(HttpContext.Current.Response, "https://login.microsoftonline.com/021af3dc-d776-4348-8539-7eab9f6ce3fb/saml2", authnRequestXml, relayState, x509Certificate.PrivateKey);
             *
             *
             * HttpContext.Current.Response.End();
             */
            //HttpContext.Current.Session["ff"] = "test";

            //object tss = HttpContext.Current.Session["ff"];

            string partnerIdP = WebConfigurationManager.AppSettings["PartnerIdP"];

            SAMLServiceProvider.InitiateSSO(HttpContext.Current.Response, null, partnerIdP);
            return(new LoginResponse());
        }
        public ActionResult Login()
        {
            var idp = WebConfigurationManager.AppSettings["PartnerIdP"];

            SAMLServiceProvider.InitiateSSO(Response, null, idp);
            return(new EmptyResult());
        }
Exemplo n.º 3
0
        protected void ssoLinkButton_Click(object sender, EventArgs e)
        {
            // To login at the service provider, initiate single sign-on to the identity provider (SP-initiated SSO).
            string partnerIdP = WebConfigurationManager.AppSettings[AppSettings.PartnerIdP];

            SAMLServiceProvider.InitiateSSO(Response, null, partnerIdP);
        }
        //[RequireHttps]
        public ActionResult Login()
        {
            // Read application's creads from the header.
            var appName  = default(string);
            var password = default(string);

            HttpBasicAuthentication.GetAuthorizationHeader(Request, out appName, out password);
            if (string.IsNullOrEmpty(appName) || string.IsNullOrEmpty(password))
            {
                return(new HttpUnauthorizedResult("Invalid username or password."));
            }

            var app = Database.FindUnique <ExternalAppDoc>(a =>
                                                           (a.Name == appName) && (a.Password == password));

            if (app == null)
            {
                return(new HttpUnauthorizedResult("Invalid username or password."));
            }

            PartnerSSOData.PartnerApp = app;

            // Request the user info from the IdP.
            SAMLServiceProvider.InitiateSSO(Response, null, app.IdP);

            return(new EmptyResult());
            //return RedirectToAction("Index", "Home");
        }
Exemplo n.º 5
0
        public ActionResult SingleSignOn()
        {
            // To login at the service provider, initiate single sign-on to the identity provider (SP-initiated SSO).
            string partnerIdP = WebConfigurationManager.AppSettings[AppSettings.PartnerIdP];

            SAMLServiceProvider.InitiateSSO(Response, null, partnerIdP);

            return(new EmptyResult());
        }
Exemplo n.º 6
0
        protected void ssoLinkButton_Click(object sender, EventArgs e)
        {
            // Remember the return URL.
            string returnUrl = Request.QueryString["ReturnUrl"];

            // To login at the service provider, initiate single sign-on to the identity provider (SP-initiated SSO).
            string partnerIdP = WebConfigurationManager.AppSettings[AppSettings.PartnerIdP];

            SAMLServiceProvider.InitiateSSO(Response, returnUrl, partnerIdP);
        }
        public ActionResult InitiateSingleSignOn(string returnUrl = null)
        {
            var partnerName = WebConfigurationManager.AppSettings["PartnerName"];

            // To login automatically at the service provider,
            // initiate single sign-on to the identity provider (SP-initiated SSO).
            // The return URL is remembered as SAML relay state.
            SAMLServiceProvider.InitiateSSO(Response, partnerName, returnUrl);

            return(new EmptyResult());
        }
Exemplo n.º 8
0
        public ActionResult SingleSignOn(string idp, string sourceDomain, string returnUrl)
        {
            // HACK: for idp affiliate testing, use the returnUrl to auto-select affiliate on idp login
            if (SAMLConfiguration.Current.IdentityProviderConfiguration != null &&
                idp == SAMLConfiguration.Current.IdentityProviderConfiguration.Name)
            {
                returnUrl = sourceDomain;
            }

            // idp maps to the name attribute of the PartnerIdentityProvider in saml.config
            SAMLServiceProvider.InitiateSSO(Response, returnUrl, idp);

            return(new EmptyResult());
        }
Exemplo n.º 9
0
        public ActionResult SingleSignOn(string idpName)
        {
            SamlPocTraceListener.Log("SAML", $"SamlController.SingleSignOn: Request for SSO with IdP {idpName} received.");

            // To login at the service provider, initiate single sign-on to the identity provider (SP-initiated SSO).
            //string partnerIdP = WebConfigurationManager.AppSettings[idpName];
            SAMLServiceProvider.InitiateSSO(Response, null, idpName);

            SamlPocTraceListener.Log("SAML", $"SamlController.SingleSignOn: SSO with IdP {idpName} initiated.");

            Session["IdentityProvider"] = idpName;

            return(new EmptyResult());
        }
Exemplo n.º 10
0
        public override object Authenticate(IServiceBase authService, IAuthSession session, Authenticate request)
        {
            if (authService.Request is IHttpRequest && (authService.Request as IHttpRequest).HttpMethod == "GET")
            {
                session.ReferrerUrl = authService.Request.QueryString["redirect"];
                authService.SaveSession(session, this.SessionExpiry);

                string partnerIdP = WebConfigurationManager.AppSettings[PartnerIdP];
                SAMLServiceProvider.InitiateSSO(HttpContext.Current.Response, null, partnerIdP);

                (HttpContext.Current.ToResponse() as AspNetResponse).End();
                return(null);
            }
            else
            {
                var    tokens         = this.Init(authService, ref session, request);
                bool   isInResponseTo = false;
                string partnerIdP     = null;
                string authnContext   = null;
                string userName       = null;
                IDictionary <string, string> attributes = null;
                string targetUrl = null;

                // Receive and process the SAML assertion contained in the SAML response.
                // The SAML response is received either as part of IdP-initiated or SP-initiated SSO.
                SAMLServiceProvider.ReceiveSSO(HttpContext.Current.Request, out isInResponseTo, out partnerIdP, out authnContext, out userName, out attributes, out targetUrl);

                // If no target URL is provided, provide a default.
                if (targetUrl == null)
                {
                    targetUrl = session.ReferrerUrl;
                }

                var authInfo = new Dictionary <string, string>
                {
                    { "username", userName },
                    { "user_id", userName }
                };

                session.IsAuthenticated = true;

                return(OnAuthenticated(authService, session, tokens, authInfo) ??
                       authService.Redirect(SuccessRedirectUrlFilter(this, targetUrl)));
            }
        }
Exemplo n.º 11
0
        public override object Authenticate(IServiceBase authService, IAuthSession session, Authenticate request)
        {
            var tokens = this.Init(authService, ref session, request);


            if (authService.Request.Verb == "POST")
            {
                bool   isInResponseTo = false;
                string partnerIdP     = null;
                string authnContext   = null;
                string userName       = null;
                IDictionary <string, string> attributes = null;
                string targetUrl = null;

                // Receive and process the SAML assertion contained in the SAML response.
                // The SAML response is received either as part of IdP-initiated or SP-initiated SSO.
                SAMLServiceProvider.ReceiveSSO(HttpContext.Current.Request, out isInResponseTo, out partnerIdP, out authnContext, out userName, out attributes, out targetUrl);

                // If no target URL is provided, provide a default.
                if (targetUrl == null)
                {
                    targetUrl = "~/";
                }

                var authInfo = new Dictionary <string, string>
                {
                    { "username", userName }
                };

                session.IsAuthenticated = true;

                return(OnAuthenticated(authService, session, tokens, authInfo) ??
                       authService.Redirect(SuccessRedirectUrlFilter(this, session.ReferrerUrl)));
            }
            else
            {
                string partnerIdP = WebConfigurationManager.AppSettings["PartnerIdP"];
                SAMLServiceProvider.InitiateSSO(HttpContext.Current.Response, null, partnerIdP);

                return(new ServiceStack.HttpResult());
            }
        }
Exemplo n.º 12
0
        public ActionResult Login(string domain, string returnUrl)
        {
            SamlPocTraceListener.Log("SAML", $"SamlController.SingleSignOn: Request for SSO with IdP of domain {domain} received.");

            // Get appropriate IdP name
            var idpName = SamlIdentityProvidersRepository.GetIdentityProviderName(domain);

            if (idpName == null)
            {
                SamlPocTraceListener.Log("SAML", $"SamlController.SingleSignOn: IdP for domain {domain} not found.");

                return(View("Error"));
            }

            // To login at the service provider, initiate single sign-on to the identity provider (SP-initiated SSO).
            SAMLServiceProvider.InitiateSSO(Response, returnUrl, idpName);

            SamlPocTraceListener.Log("SAML", $"SamlController.SingleSignOn: SSO with IdP {idpName} initiated.");

            return(new EmptyResult());
        }
Exemplo n.º 13
0
        public ActionResult InitiateSingleSignOn(string relayState = null)
        {
            try
            {
                // RequestLoginAtIdentityProvider();

                var path = Server.MapPath("~/Certificates/sp.pfx");
                new X509Certificate(path, "activants", X509KeyStorageFlags.MachineKeySet);
                var serviceId   = "";
                var partnerName = "";
                if (Request.QueryString.ToString().Length > 0)
                {
                    Dictionary <string, string> dictionary = new Dictionary <string, string>();
                    dictionary["AuthorityURL"] = Request.UrlReferrer.GetLeftPart(UriPartial.Authority);
                    dictionary["returnURL"]    = Request.QueryString["returnURL"];
                    relayState = string.Join(";", dictionary);
                    var ClientAuthorityUrl = Request.UrlReferrer.GetLeftPart(UriPartial.Authority);
                    var ClientReturnUrl    = Request.QueryString["returnURL"];

                    relayState = RelayStateCache.Add(new RelayState(ClientAuthorityUrl, null));
                    relayState = RelayStateCache.Add(new RelayState(ClientReturnUrl, null));

                    serviceId = Request.QueryString["samlConfigurationId"];
                }
                if (serviceId == "")
                {
                    partnerName = WebConfigurationManager.AppSettings["ActivantsSAMLSP1IDPName"];
                    SAMLController.ConfigurationID = "ActivantsSAMLSP1";
                    // XmlElement authnRequestXml = SAMLController.ConfigurationID;
                    //HTTPArtifactState httpArtifactState = new HTTPArtifactState(SAMLController.ConfigurationID, null);
                    bool value = SamlAuthorizedDomains.IsAutorizedUrl(Request.Url.GetLeftPart(UriPartial.Authority));
                    if (value)
                    {
                        //string idpURL = CreateSSOServiceURL();
                        //ServiceProvider.SendArtifactByHTTPArtifact(Response, idpURL, httpArtifact, relayState, false);
                        SAMLServiceProvider.InitiateSSO(Response, relayState, partnerName, new SSOOptions()
                        {
                            ForceAuthn = true
                        });
                    }
                }
                else
                {
                    var partnerId = serviceId + "IDPName";
                    partnerName = WebConfigurationManager.AppSettings[partnerId];
                    SAMLController.ConfigurationID = serviceId;
                    bool value = SamlAuthorizedDomains.IsAutorizedUrl(Request.UrlReferrer.GetLeftPart(UriPartial.Authority));
                    if (value)
                    {
                        SAMLServiceProvider.InitiateSSO(Response, relayState, partnerName, new SSOOptions()
                        {
                            ForceAuthn = true
                        });
                    }
                }
                return(new EmptyResult());
            }
            catch (Exception e)
            {
                if (Request.QueryString.ToString().Length > 0)
                {
                    var ReturnUrl = Request.UrlReferrer.GetLeftPart(UriPartial.Authority);
                    TempData["error"]          = e;
                    TempData["ReturnURL"]      = ReturnUrl;
                    ViewBag.JavaScriptFunction = ReturnUrl;
                    return(RedirectToAction("error", "Home"));
                }
                else
                {
                    TempData["err"] = e;
                    return(RedirectToAction("index", "Home"));
                }
            }
        }
Exemplo n.º 14
0
        protected void ssoLinkButton_Click(object sender, EventArgs e)
        {
            string partnerIdP = WebConfigurationManager.AppSettings[AppSettings.PartnerIdP];

            SAMLServiceProvider.InitiateSSO(Response, null, partnerIdP);
        }