<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>English archivos - KumbiaPHP Framework PHP en español</title>
	<atom:link href="https://kumbiaphp.com/blog/category/english/feed/" rel="self" type="application/rss+xml" />
	<link>https://kumbiaphp.com/blog/category/english/</link>
	<description>Web &#38; app MVC PHP framework</description>
	<lastBuildDate>Fri, 22 Dec 2017 12:05:51 +0000</lastBuildDate>
	<language>es</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.3</generator>

<image>
	<url>https://kumbiaphp.com/blog/wp-content/uploads/2016/01/250-150x150.png</url>
	<title>English archivos - KumbiaPHP Framework PHP en español</title>
	<link>https://kumbiaphp.com/blog/category/english/</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">123854898</site>	<item>
		<title>Now KumbiaPHP is on Slack</title>
		<link>https://kumbiaphp.com/blog/2015/12/13/now-kumbiaphp-is-on-slack/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=now-kumbiaphp-is-on-slack</link>
					<comments>https://kumbiaphp.com/blog/2015/12/13/now-kumbiaphp-is-on-slack/#respond</comments>
		
		<dc:creator><![CDATA[Alberto Berroteran]]></dc:creator>
		<pubDate>Sun, 13 Dec 2015 15:14:01 +0000</pubDate>
				<category><![CDATA[Comunidad]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[PHP]]></category>
		<guid isPermaLink="false">http://www.kumbiaphp.com/blog/?p=919</guid>

					<description><![CDATA[<p>Hi, Now KumbiaPHP is on Slack. Please, use Slack, The IRC channel is deprecated. PD: Sorry for my accent,&#8230;</p>
<p>La entrada <a href="https://kumbiaphp.com/blog/2015/12/13/now-kumbiaphp-is-on-slack/">Now KumbiaPHP is on Slack</a> se publicó primero en <a href="https://kumbiaphp.com/blog">KumbiaPHP Framework PHP en español</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><iframe src="https://www.youtube.com/embed/PzF4bz64Wp0" width="940" height="529" frameborder="0" allowfullscreen="allowfullscreen"></iframe></p>
<p>Hi, Now KumbiaPHP is on Slack. Please, use Slack, The IRC channel is deprecated.</p>
<p><strong>PD:</strong> Sorry for my accent, it&#8217;s my first video. <a href="http://slack.kumbiaphp.com/">http://slack.kumbiaphp.com/</a> and <a href="https://kumbiaphp.slack.com/" target="_blank" rel="noopener">https://kumbiaphp.slack.com/</a></p>
<p>La entrada <a href="https://kumbiaphp.com/blog/2015/12/13/now-kumbiaphp-is-on-slack/">Now KumbiaPHP is on Slack</a> se publicó primero en <a href="https://kumbiaphp.com/blog">KumbiaPHP Framework PHP en español</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://kumbiaphp.com/blog/2015/12/13/now-kumbiaphp-is-on-slack/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">919</post-id>	</item>
		<item>
		<title>How to create a REST Service with Basic Auth in KumbiaPHP</title>
		<link>https://kumbiaphp.com/blog/2015/10/26/how-to-create-a-rest-service-with-basic-auth-in-kumbiaphp/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-create-a-rest-service-with-basic-auth-in-kumbiaphp</link>
					<comments>https://kumbiaphp.com/blog/2015/10/26/how-to-create-a-rest-service-with-basic-auth-in-kumbiaphp/#respond</comments>
		
		<dc:creator><![CDATA[Alberto Berroteran]]></dc:creator>
		<pubDate>Mon, 26 Oct 2015 02:04:16 +0000</pubDate>
				<category><![CDATA[English]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[API]]></category>
		<guid isPermaLink="false">http://www.kumbiaphp.com/blog/?p=900</guid>

					<description><![CDATA[<p>In the last post, we explained how to create a basic REST service. But everybody can access to it.&#8230;</p>
<p>La entrada <a href="https://kumbiaphp.com/blog/2015/10/26/how-to-create-a-rest-service-with-basic-auth-in-kumbiaphp/">How to create a REST Service with Basic Auth in KumbiaPHP</a> se publicó primero en <a href="https://kumbiaphp.com/blog">KumbiaPHP Framework PHP en español</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In the last <a href="https://www.kumbiaphp.com/blog/2015/02/03/servicios-rest-con-kumbiaphp/" target="_blank" rel="noopener">post</a>, we explained how to create a basic REST service. But everybody can access to it. What do if we want to make it  accessible only for authenticated users? There are a few authentication methods for REST service, and the most used of them is the <a href="https://en.wikipedia.org/wiki/OAuth" target="_blank" rel="noopener">OAuth, </a>but today we shall speak about another  method more simple called <a href="https://en.wikipedia.org/wiki/Basic_access_authentication" target="_blank" rel="noopener">Basic Auth</a>.</p>
<p><span id="more-900"></span></p>
<p>We shall skip the database connection and we shall use a static array for the data. This is the PHP code:</p>
<p>File: <em>app/controllers/framework_controller.php</em></p>
<pre><code class="language-php">
&lt;?php

class FrameworkController extends RestController {

    protected $fw = array(1 =&gt; array(
            &quot;name&quot; =&gt; &quot;KumbiaPHP&quot;,
            &quot;description&quot; =&gt; &quot;The best PHP framework on the world&quot;
        ),
        array(
            &quot;name&quot; =&gt; &quot;Laravel&quot;,
            &quot;description&quot; =&gt; &quot;The new boy in the neighbourhood&quot;
        ),
        array(
            &quot;name&quot; =&gt; &quot;Symfony&quot;,
            &quot;description&quot; =&gt; &quot;The old veteran man&quot;
        ),
    );

    public function get($id) {
        if (isset($this-&gt;fw[$id])) {
            $this-&gt;data = $this-&gt;fw[$id];
        } else {
            $this-&gt;error(&#039;This framework doesn\&#039;t exist&#039;, 404);
        }
    }

    public function getAll() {
        $this-&gt;data = $this-&gt;fw;
    }

}
</code></pre>
<p>We created a new controller called Framework controller with two actions: <em>getAll</em> for getting all frameworks, and <em>get</em> for getting a framework by id. But this controller is still accessible for all users.  Now, we shall open the <em>rest_controller.php</em> file <span id="result_box" class="short_text" lang="en"><span class="hps">located in the directory</span></span><em> default\app\libs. </em>Add the user&#8217;s data for the authentication in an array and add the  validation in the initialize method.</p>
<pre><code class="language-php">
&lt;?php

require_once CORE_PATH . &#039;kumbia/kumbia_rest.php&#039;;

class RestController extends KumbiaRest {

    protected $users = array(
        &#039;alberto&#039; =&gt; &#039;123456&#039;,
        &#039;ashrey&#039; =&gt; &#039;0000&#039;
    );

    final protected function initialize() {
        $user = isset($_SERVER[&#039;PHP_AUTH_USER&#039;]) ? filter_var($_SERVER[&#039;PHP_AUTH_USER&#039;]) : null;
        $pass = isset($_SERVER[&#039;PHP_AUTH_PW&#039;]) ? filter_var($_SERVER[&#039;PHP_AUTH_PW&#039;]) : null;
        if (isset($this-&gt;users[$user]) &amp;&amp; ($this-&gt;users[$user] == $pass)) {
            return true;
        } else {
            $this-&gt;data = $this-&gt;error(&quot;Fail authentication&quot;, 401);
            header(&#039;WWW-Authenticate: Basic realm=&quot;Private Area&quot;&#039;);
            return false;
        }
    }

    final protected function finalize() {
        
    }

}
</code></pre>
<p>Now, you need to send a valid user and password for access to the results. You can use a tool like Postman or HttpRequester for to test, or your browser. Using Firefox, you will look a dialogue like:</p>
<p><a href="https://www.kumbiaphp.com/blog/wp-content/uploads/2015/10/2.png"><img decoding="async" class="size-medium wp-image-903" src="https://www.kumbiaphp.com/blog/wp-content/uploads/2015/10/2-300x103.png" alt="auth dialog" width="300" height="103" srcset="https://kumbiaphp.com/blog/wp-content/uploads/2015/10/2-300x103.png 300w, https://kumbiaphp.com/blog/wp-content/uploads/2015/10/2.png 589w" sizes="(max-width: 300px) 100vw, 300px" /></a><br />
 If you type a correct user and password you can see a page like:</p>
<p><a href="https://www.kumbiaphp.com/blog/wp-content/uploads/2015/10/3.png"><img fetchpriority="high" decoding="async" class="alignnone size-medium wp-image-904" src="https://www.kumbiaphp.com/blog/wp-content/uploads/2015/10/3-300x189.png" alt="Frameworks list" width="300" height="189" srcset="https://kumbiaphp.com/blog/wp-content/uploads/2015/10/3-300x189.png 300w, https://kumbiaphp.com/blog/wp-content/uploads/2015/10/3.png 480w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>else you will see a page like:</p>
<p><a href="https://www.kumbiaphp.com/blog/wp-content/uploads/2015/10/1.png"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-906" src="https://www.kumbiaphp.com/blog/wp-content/uploads/2015/10/1.png" alt="Fail authentication" width="277" height="95" /></a></p>
<p>La entrada <a href="https://kumbiaphp.com/blog/2015/10/26/how-to-create-a-rest-service-with-basic-auth-in-kumbiaphp/">How to create a REST Service with Basic Auth in KumbiaPHP</a> se publicó primero en <a href="https://kumbiaphp.com/blog">KumbiaPHP Framework PHP en español</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://kumbiaphp.com/blog/2015/10/26/how-to-create-a-rest-service-with-basic-auth-in-kumbiaphp/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">900</post-id>	</item>
	</channel>
</rss>
