{"id":151,"date":"2019-11-28T13:17:16","date_gmt":"2019-11-28T12:17:16","guid":{"rendered":"http:\/\/blog.remyblom.nl\/?p=151"},"modified":"2020-11-17T10:20:57","modified_gmt":"2020-11-17T09:20:57","slug":"simplesamlphp-as-a-service-provider-with-nginx","status":"publish","type":"post","link":"https:\/\/blog.remyblom.nl\/?p=151","title":{"rendered":"SimpleSAMLphp as  a Service Provider with Nginx!"},"content":{"rendered":"\n<p>On a server with nginx already setup, I wanted to write a php-application that needed SAML-authentication. So let&#8217;s install SimpleSAMLphp and configure it and nginx to have the magic going. I presume you have a user with sudo privileges that is also member of the www-data group.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ cd \/var\/www\n$ sudo chown root:www-data .\n$ sudo chmod 775 .\n$ wget -O simplesaml.tar.gz https:\/\/simplesamlphp.org\/download?latest\n$ tar xzf simplesaml.tar.gz\n$ ln -sf simplesamlphp-1.18.x\/ simplesamlphp<\/code><\/pre>\n\n\n\n<p>Now that we have a simpleSAMLphp installation let&#8217;s configure it, edit <code>config\/config.php<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ I like short baseurlpaths:\n'baseurlpath' => 'https:\/\/application.example.org\/saml\/',\n\n\/\/ I always fill in the technical contact information:\n'technicalcontact_name' => 'Remy Blom',\n'technicalcontact_email' => 'na@example.org',\n\n'timezone' => 'Europe\/Amsterdam',\n\n\/\/ https:\/\/passwordsgenerator.net\/ \n\/\/ length = 32, include numbers and lowercase characters\n'secretsalt' => 'ner9iuf8vu3fqkgawqchu7bcp4ihn221',\n   \n\/\/ you might want to change this one: \n'auth.adminpassword' => '123',\n \n'admin.protectindexpage' => true,<\/code><\/pre>\n\n\n\n<p>Now let&#8217;s setup nginx to serve simpleSAMLphp from the <code>\/saml<\/code> url: in <code>\/var\/www\/html\/<\/code> I create a symlink:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ sudo ln -sf \/var\/www\/simplesamlphp\/www \/var\/www\/html\/saml<\/code><\/pre>\n\n\n\n<p>And presuming you already have a serverblock setup that is serving <code>\/var\/www\/html<\/code>  we can add this location-block:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>location \/saml {\n  location ~ ^(?&lt;prefix>\/saml)(?&lt;phpfile>.+?\\.php)(?&lt;pathinfo>\/.*)?$ {\n    include snippets\/fastcgi-php.conf;\n    fastcgi_pass     unix:\/var\/run\/php\/php7.2-fpm.sock;\n    fastcgi_split_path_info ^((?U).+\\.php)(\/?.+)$; \n  }\n}<\/code><\/pre>\n\n\n\n<p>Reload nginx:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ sudo nginx -t &amp;&amp; sudo service nginx reload<\/code><\/pre>\n\n\n\n<p>In <code>\/config\/authsources.php<\/code> we put:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\n$config = [\n  \/\/ This is a authentication source which handles admin authentication.\n  'admin' => [\n    \/\/ The default is to use core:AdminPassword, but it can be replaced with\n    \/\/ any authentication source.\n    'core:AdminPassword',\n  ],\n\n  \/\/ An authentication source which can authenticate against both SAML 2.0\n  \/\/ and Shibboleth 1.3 IdPs.\n  'application.example.org' => [\n    'saml:SP',\n    'entityID' => 'https:\/\/application.example.org',\n    'idp' => 'https:\/\/idp.example.org',\n  ],\n];<\/code><\/pre>\n\n\n\n<p>Then we exchange the metadata with the IdP and we have a testable setup. You can use https:\/\/application.example.org\/saml\/module.php\/core\/authenticate.php to test the application as an authentication source. You should be able to login via your IdP<\/p>\n\n\n\n<p>If so, writing a simple php program that needs authentication is peanuts:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\nrequire_once('\/var\/www\/simplesamlphp\/lib\/_autoload.php');\n\n$as = new \\SimpleSAML\\Auth\\Simple('application.example.org');\n$as->requireAuth();\n$attr = $as->getAttributes();\n\nprint_r($attr);<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>On a server with nginx already setup, I wanted to write a php-application that needed SAML-authentication. So let&#8217;s install SimpleSAMLphp and configure it and nginx to have the magic going. I presume you have a user with sudo privileges that is also member of the www-data group. Now that we have a simpleSAMLphp installation let&#8217;s &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.remyblom.nl\/?p=151\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;SimpleSAMLphp as  a Service Provider with Nginx!&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15,6],"tags":[],"class_list":["post-151","post","type-post","status-publish","format-standard","hentry","category-config","category-php"],"_links":{"self":[{"href":"https:\/\/blog.remyblom.nl\/index.php?rest_route=\/wp\/v2\/posts\/151","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.remyblom.nl\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.remyblom.nl\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.remyblom.nl\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.remyblom.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=151"}],"version-history":[{"count":2,"href":"https:\/\/blog.remyblom.nl\/index.php?rest_route=\/wp\/v2\/posts\/151\/revisions"}],"predecessor-version":[{"id":154,"href":"https:\/\/blog.remyblom.nl\/index.php?rest_route=\/wp\/v2\/posts\/151\/revisions\/154"}],"wp:attachment":[{"href":"https:\/\/blog.remyblom.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=151"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.remyblom.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=151"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.remyblom.nl\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=151"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}