コード例 #1
0
        public ActionResult Index()
        {
            if (true)
            {
                if (!Request.IsAuthenticated)
                {
                    //TODO: specify the SAML provider url here, aka "Endpoint"
                    var samlEndpoint = "https://login.microsoftonline.com/cdd071d0-805d-4b10-bac9-ee8225b4cbdc/saml2"; //"http://saml-provider-that-we-use.com/login/";

                    var request = new AuthRequest(
                        "599e9d7b-b868-4aaf-b422-85fe1d29c37e",    //TODO: put your app's "unique ID" here
                        "https://localhost:44370/Home/SamlConsume" //TODO: put Assertion Consumer URL (where the provider should redirect users after authenticating)
                        );

                    //redirect the user to the SAML provider
                    return(Redirect(request.GetRedirectUrl(samlEndpoint)));
                }
                else
                {
                    return(View());
                }
            }
            else
            {
                return(View());
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            DateTime dt1970          = new DateTime(1970, 1, 1);
            DateTime current         = DateTime.UtcNow; //DateTime.Now;//DateTime.UtcNow for unix timestamp
            TimeSpan span            = current - dt1970;
            long     timestampinlong = (long)span.TotalMilliseconds;
            //String expiry_tmestamp = Decrypt(ConfigurationManager.AppSettings["issue"]);
            //if (Convert.ToInt64(expiry_tmestamp) > timestampinlong)
            //{
            var samlEndpoint = ConfigurationManager.AppSettings["idp_ssourl"].TrimStart().TrimEnd();
            // Response.Write("IDP_sso" + samlEndpoint);
            var request = new AuthRequest(
                ConfigurationManager.AppSettings["sp_entityid"].TrimStart().TrimEnd(),  //put your app's "unique ID" here
                ConfigurationManager.AppSettings["sp_acsurl"].TrimStart().TrimEnd()     //assertion Consumer Url - the URL where provider will redirect authenticated users after authenticating them
                );

            var relay = "";

            if (Request.QueryString["relayState"] != null)
            {
                relay = Request.QueryString["relaystate"].ToString();
            }
            string url = request.GetRedirectUrl(samlEndpoint, relay);

            Response.Redirect(url);

            //then redirect your user to the above "url" var
            //for example, like this:
            //}
            //else
            //{
            //   Response.Write("Expired");
            // }
        }
コード例 #3
0
        public static string CallProvider(string samlEndpoint, AuthRequest request)
        {
            //generate the provider URL
            string url = request.GetRedirectUrl(samlEndpoint);

            //then redirect your user to the above "url" var
            //for example, like this:
            return(url);
        }
コード例 #4
0
        public ActionResult SamlTest()
        {
            AccountSettings accountSettings = new AccountSettings();

            AuthRequest req = new AuthRequest(new AppSettings(),
                                              accountSettings);

            string url = req.GetRedirectUrl(accountSettings.idp_sso_target_url);

            return(Redirect(url));
        }
コード例 #5
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            var samlEndpoint = "http://saml-provider-that-we-use.com/login/";

            var request = new AuthRequest(
                "http://www.myapp.com",            //TODO: put your app's "unique ID" here
                "http://www.myapp.com/SamlConsume" //TODO: put Assertion Consumer URL (where the provider should redirect users after authenticating)
                );

            Response.Redirect(request.GetRedirectUrl(samlEndpoint));
            //redirect the user to the SAML provider
        }
コード例 #6
0
        /// <summary> Returns the url used to perform SAML single sign in with Azure active directory.
        /// </summary>
        /// <returns></returns>
        string GetRedirectUrl()
        {
            AuthRequest auth = new AuthRequest(
                Constants.APP_ID,        // put your app's "unique ID" here
                Constants.REPLY_URL      // assertion Consumer Url - the redirect URL where the provider will send authenticated users
                );

            // goto the micrsoft login page
            string sso_redirect = auth.GetRedirectUrl(Constants.SAML_ENDPOINT);

            return(sso_redirect);
        }
コード例 #7
0
ファイル: AccountController.cs プロジェクト: MarvinZ/SSOPOC5
        //[ValidateAntiForgeryToken]
        public ActionResult Login2()
        {
            //TODO: specify the SAML provider url here, aka "Endpoint"
            var samlEndpoint = "https://dev-292023.okta.com/app/cbredev292023_mftest102_1/exkn9uxdur7BCIAHP4x6/sso/saml";

            var request = new AuthRequest(
                "testClient1",                     //TODO: put your app's "unique ID" here
                "http://www.myapp.com/SamlConsume" //TODO: put Assertion Consumer URL (where the provider should redirect users after authenticating)
                );

            //redirect the user to the SAML provider
            return(Redirect(request.GetRedirectUrl(samlEndpoint)));
        }
コード例 #8
0
        // GET: LogOn
        public ActionResult LogOn()
        {
            var samlEndpoint = WebConfigurationManager.AppSettings["samlEndpoint"];

            var request = new AuthRequest("", "");
            //generate the provider URL
            string url = request.GetRedirectUrl(samlEndpoint);

            //then redirect your user to the above "url" var
            //for example, like this:

            Response.Redirect(url);
            return(View());
        }
コード例 #9
0
ファイル: Default.aspx.cs プロジェクト: mat-chet/C-
    protected void Page_Load(object sender, EventArgs e)
    {
        AccountSettings accountSettings = new AccountSettings();
        AppSettings settings = new AppSettings();
        AuthRequest req = new AuthRequest(settings.issuer,settings.assertionConsumerServiceUrl);

        XmlDocument doc11 = new XmlDocument();

        /*doc11.LoadXml(Encoding.UTF8.GetString(Convert.FromBase64String(req.GetRequest(AuthRequest.AuthRequestFormat.Base64))));
        using (XmlTextWriter xmltw = new XmlTextWriter("C:\\Users\\Matvey\\source\\repos\\SamlTestApp\\SamlTestApp\\exampleRequest.xml", new UTF8Encoding(false)))
        {
            doc11.WriteTo(xmltw);

            xmltw.Close();
        }*/

        Response.Redirect(req.GetRedirectUrl(accountSettings.idp_sso_target_url));
    }
コード例 #10
0
        public void TestGetReplyUrl()
        {
            AuthRequest auth_request = new AuthRequest(TEST_SERVICE_PROVIDER_URL, TEST_REPLY_URL);

            string redirect_url = auth_request.GetRedirectUrl(SAML_ENDPOINT);

            // reverse the process applied by the SAML library to get the request XML
            // Undo UrlEncode => Undo Base64
            int    request_index     = redirect_url.IndexOf("SAMLRequest=") + "SAMLRequest=".Length;
            string saml_request      = redirect_url.Substring(request_index);
            string url_param_decoded = HttpUtility.UrlDecode(saml_request);

            byte[] base64_decoded_bytes = Convert.FromBase64String(url_param_decoded);

            // apply the deflate decompression algorithm to decompress the result
            var memory_stream  = new MemoryStream(base64_decoded_bytes);
            var deflate_stream = new DeflateStream(memory_stream, CompressionMode.Decompress);

            byte[] output_array = new byte[1000];

            deflate_stream.Read(output_array, 0, 1000);
            string xml_string = Encoding.UTF8.GetString(output_array);

            // convert the decompressed bytes into an XMl document
            XmlDocument xml_doc = new XmlDocument();

            xml_doc.LoadXml(xml_string);

            // microsoft complains about not using a namespace
            XmlNamespaceManager manager = new XmlNamespaceManager(xml_doc.NameTable);

            manager.AddNamespace("samlp", "urn:oasis:names:tc:SAML:2.0:protocol");
            manager.AddNamespace("saml", "urn:oasis:names:tc:SAML:2.0:assertion");

            XmlNode node = xml_doc.SelectSingleNode("/samlp:AuthnRequest", manager);
            XmlAttributeCollection node_attributes = node.Attributes;
            string reply_url = node_attributes["AssertionConsumerServiceURL"].Value;

            node = xml_doc.SelectSingleNode("/samlp:AuthnRequest/saml:Issuer", manager);
            string service_provider_url = node.InnerText;

            Assert.AreEqual(TEST_REPLY_URL, reply_url);
            Assert.AreEqual(TEST_SERVICE_PROVIDER_URL, service_provider_url);
        }
コード例 #11
0
        public void TestGetRequestUrlNull()
        {
            AuthRequest auth_request = new AuthRequest(TEST_SERVICE_PROVIDER_URL, TEST_REPLY_URL);

            Assert.ThrowsException <NullReferenceException>(() => { string redirect_url = auth_request.GetRedirectUrl(null); });
        }