# Build a Simple Laravel App with Authentication

**URL:** <https://devforum.okta.com/t/build-a-simple-laravel-app-with-authentication/17133>\
**Category:** Developer Blog Comments\
**Created:** [September 5, 2019, 12:16am UTC](https://devforum.okta.com/t/build-a-simple-laravel-app-with-authentication/17133 "2019-09-05T00:16:08Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [September 5, 2019, 12:16am UTC](https://devforum.okta.com/t/build-a-simple-laravel-app-with-authentication/17133/1 "2019-09-05T00:16:08Z")

</div>

[Build a Simple Laravel App with Authentication](https://developer.okta.com/blog/2019/09/05/laravel-authentication)

Let’s build a simple Laravel app and add authentication with a custom identity provider.

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [January 23, 2020, 10:13pm UTC](https://devforum.okta.com/t/build-a-simple-laravel-app-with-authentication/17133/2 "2020-01-23T22:13:32Z")

</div>

**Pavel Smirnov**

Unfortunately coming across issues with Laravel 6… Once we’ve passed the main hurdles with Okta providers and array\_get and fixed the URL we’re now getting:

BadMethodCallException  
Method App\Http\Controllers\Auth\LoginController::showLoginForm does not exist.

Indeed controller is no longer using Authenticates trait… Is this a known issue or has Laravel 6 been tested ?

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [January 23, 2020, 10:15pm UTC](https://devforum.okta.com/t/build-a-simple-laravel-app-with-authentication/17133/3 "2020-01-23T22:15:34Z")

</div>

**aaronpk**

This blog post is written for Laravel 5. We will hopefully be able to publish an updated tutorial for Laravel 6 in the future.

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [January 23, 2020, 10:17pm UTC](https://devforum.okta.com/t/build-a-simple-laravel-app-with-authentication/17133/4 "2020-01-23T22:17:22Z")

</div>

**Pavel Smirnov**

Would that be sooner rather than later? Just trying to figure out the amount of effort we shall put into it right now…

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [January 23, 2020, 10:18pm UTC](https://devforum.okta.com/t/build-a-simple-laravel-app-with-authentication/17133/5 "2020-01-23T22:18:40Z")

</div>

**aaronpk**

It’s not scheduled on our calendar yet so I would say you shouldn’t wait for us. If you do figure it out, please post any notes as a new comment here so others can find it too!

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [January 23, 2020, 10:19pm UTC](https://devforum.okta.com/t/build-a-simple-laravel-app-with-authentication/17133/6 "2020-01-23T22:19:17Z")

</div>

**Krasimir Hristozov**

@disqus\_ObMm9bHisQ I’ll have a look at it over the weekend and see if I can help you. It should be a simple fix since there aren’t huge differences between Laravel 6 and 5.8. In any case, I’ll let you know how difficult it would be to fix even if I can’t provide the solution.

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [January 23, 2020, 10:23pm UTC](https://devforum.okta.com/t/build-a-simple-laravel-app-with-authentication/17133/7 "2020-01-23T22:23:12Z")

</div>

**Pavel Smirnov**

Much appreciated 🙂

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [January 23, 2020, 10:23pm UTC](https://devforum.okta.com/t/build-a-simple-laravel-app-with-authentication/17133/8 "2020-01-23T22:23:50Z")

</div>

**Pavel Smirnov**

We’ll see if we can have a quick fix and if not I’ll talk to dev team as to how much are they locked into Laravel 6…

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [January 27, 2020, 12:27am UTC](https://devforum.okta.com/t/build-a-simple-laravel-app-with-authentication/17133/9 "2020-01-27T00:27:42Z")

</div>

**Krasimir Hristozov**

@disqus\_ObMm9bHisQ I bumped the framework version in composer.json to 6.\* and ran composer update. It upgraded Laravel to 6.12.0.

After that, I got the array\_get error and switched “socialiteproviders/okta” to “dev-master” in composer.json (this is the suggested solution until the official fix is released).

After that, I was able to login with Okta immediately and everything worked as expected (the Dashboard, the Personal Home Page link, etc).

I’m not sure what you mean by ‘fixed the URL’ but I didn’t have to do anything except these two changes in composer.json:

“laravel/framework”: “6.\*”,  
“socialiteproviders/okta”: "dev-master"

So it seems to me that you have a different problem which is not related to Laravel 6. Probably something’s misconfigured regarding your Okta account, or you missed a step in the tutorial. Can you start the tutorial in Laravel 5.8, as it was originally designed for that version, make sure it works and then upgrade to Laravel 6 as I did?

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [January 27, 2020, 12:30am UTC](https://devforum.okta.com/t/build-a-simple-laravel-app-with-authentication/17133/10 "2020-01-27T00:30:53Z")

</div>

**Krasimir Hristozov**

@disqus\_ObMm9bHisQ

BTW, the Login controller doesn’t need the showLoginForm() method because it should never show a local login form. It only needs the methods that are implemented (redirectToProvider, handleProviderCallback, and Logout) to work with Okta as the authentication provider, so it doesn’t include the standard Laravel trait AuthenticatesUsers.

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [January 27, 2020, 1:43pm UTC](https://devforum.okta.com/t/build-a-simple-laravel-app-with-authentication/17133/11 "2020-01-27T13:43:37Z")

</div>

**Pavel Smirnov**

Lovely!   
We have now done a fresh 5.8 deployment and its working! I’ll try upgrading to Laravel 6 as you suggest.

Unrelated issue - I was trying to include custom directory profile fields into a user information request by adding a claim for this field, but not sure if I’m using the right API and am not sure how to get this.

$token = Auth::user()-\>token;  
 $user = Socialite::driver(‘okta’)-\>userFromToken($token);  
^^ does not seem to include my fields into either main array or as part of “user” element.

Interestingly if I do the token request sample from Okta UI it looks to be coming through.

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [February 12, 2020, 6:34pm UTC](https://devforum.okta.com/t/build-a-simple-laravel-app-with-authentication/17133/12 "2020-02-12T18:34:02Z")

</div>

**Larry**

Thanks for that!

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [February 12, 2020, 6:34pm UTC](https://devforum.okta.com/t/build-a-simple-laravel-app-with-authentication/17133/13 "2020-02-12T18:34:56Z")

</div>

**Larry**

How can you check the Okta org each time the page is loaded? We are having issues where users are signing out of Okta but they are still signed in to our Laravel application.

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [February 12, 2020, 6:45pm UTC](https://devforum.okta.com/t/build-a-simple-laravel-app-with-authentication/17133/14 "2020-02-12T18:45:56Z")

</div>

**Krasimir Hristozov**

This is a good question, and I recommend you to look at this article which discusses this problem (local authentication vs remote authentication):  
[https://developer.okta.com/…](https://developer.okta.com/blog/2020/01/15/protecting-a-php-api-with-oauth "https://developer.okta.com/blog/2020/01/15/protecting-a-php-api-with-oauth")

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [February 13, 2020, 2:42am UTC](https://devforum.okta.com/t/build-a-simple-laravel-app-with-authentication/17133/15 "2020-02-13T02:42:20Z")

</div>

**Larry**

Hi @krasimirhristozov , thank you for the reference. Seems like the general idea I’m trying to implement. In fact, I added a middleware to my Laravel application to check the JWT token, but am getting an error that the “kid” is invalid. I had a similar issue a while ago when authenticating API request. See [this GitHub issue](https://github.com/okta/okta-jwt-verifier-php/issues/33 "https://github.com/okta/okta-jwt-verifier-php/issues/33"). I also posted on Laracasts about it [here](https://laracasts.com/discuss/channels/laravel/socialite-middleware-to-check-if-authenticated "https://laracasts.com/discuss/channels/laravel/socialite-middleware-to-check-if-authenticated"). Feel free to chime in if you have any other thoughts. Thanks again!

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [March 3, 2020, 7:01pm UTC](https://devforum.okta.com/t/build-a-simple-laravel-app-with-authentication/17133/16 "2020-03-03T19:01:43Z")

</div>

**David Moore**

Could you share what you did to overcome array\_get issue?

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [March 5, 2020, 6:14pm UTC](https://devforum.okta.com/t/build-a-simple-laravel-app-with-authentication/17133/17 "2020-03-05T18:14:26Z")

</div>

**David Moore**

Passing in the token I get from Auth::user-\>token into

$jwtVerifier = (new \Okta\JwtVerifier\JwtVerifierBuilder())  
 -\>setDiscovery(new \Okta\JwtVerifier\Discovery\Oauth)  
 -\>setAdaptor(new \Okta\JwtVerifier\Adaptors\FirebasePhpJwt)  
 -\>setAudience(‘api://default’)  
 -\>setClientId(env(‘OKTA\_CLIENT\_ID’))  
 -\>setIssuer(env(‘OKTA\_BASE\_URL’).’/oauth2/default’)  
 -\>build();

$jwt = $jwtVerifier-\>verify($token)

results in this error: “kid” invalid, unable to lookup correct key

What am I doing wrong?

[https://github.com/okta/okt…](https://github.com/okta/okta-jwt-verif "https://github.com/okta/okta-jwt-verif")

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [March 5, 2020, 6:15pm UTC](https://devforum.okta.com/t/build-a-simple-laravel-app-with-authentication/17133/18 "2020-03-05T18:15:54Z")

</div>

**David Moore**

I am having the same issue, but it seems the lack of real dev support will not resolve this.

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [March 6, 2020, 12:15pm UTC](https://devforum.okta.com/t/build-a-simple-laravel-app-with-authentication/17133/19 "2020-03-06T12:15:20Z")

</div>

**Krasimir Hristozov**

Hi @disqus\_nZHnj1qSyB ,

I don’t maintain the okta-jwt-verifier-php library, but I’ll have a look and try to help you.

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [May 14, 2020, 8:35am UTC](https://devforum.okta.com/t/build-a-simple-laravel-app-with-authentication/17133/20 "2020-05-14T08:35:28Z")

</div>

**Muhammad Razi Bin Mohd**

Hi could I check if this package is using SAML or OAuth?

[Next page](https://devforum.okta.com/t/build-a-simple-laravel-app-with-authentication/17133.md?page=2)
