# Multiple authentication methods (form and JWT)

**URL:** <https://discourse.cakephp.org/t/multiple-authentication-methods-form-and-jwt/5005>\
**Category:** Need Help\
**Created:** [September 26, 2018, 12:08pm UTC](https://discourse.cakephp.org/t/multiple-authentication-methods-form-and-jwt/5005 "2018-09-26T12:08:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![okelet](https://avatars.discourse-cdn.com/v4/letter/o/919ad9/32.png) [@okelet](https://discourse.cakephp.org/u/okelet)\
**Post date:** [September 26, 2018, 12:08pm UTC](https://discourse.cakephp.org/t/multiple-authentication-methods-form-and-jwt/5005/1 "2018-09-26T12:08:39Z")

</div>

Hi, I have read the documentation, but it is not clear for me. I want to allow users to access using the web interface (username/password with session/cookies, but not SPA), but also programatically using JWT (making it compatible in a future with SPA). How can I configure Auth to first try with form credentials, and if not found, try with JWT header? I am using CakePHP 3.6 and admad/cakephp-jwt-auth 2.3.2

---

<div class="post-metadata">

**Author:** ![justinkbug](https://avatars.discourse-cdn.com/v4/letter/j/d2c977/32.png) [@justinkbug](https://discourse.cakephp.org/u/justinkbug)\
**Post date:** [September 29, 2018, 4:23pm UTC](https://discourse.cakephp.org/t/multiple-authentication-methods-form-and-jwt/5005/2 "2018-09-29T16:23:48Z")

</div>

I don’t know much about admad/cakephp-jwt-auth, but I’ve recently done an implementation with Okta using their jwt verifier. In cake you normall call $this-\>Auth-\>login() to log someone in. I don’t see any reason that you couldn’t attempt normal CakePHP authentication and then if it fails, attempt other means of authentication. Once you have authenticated data, you could call $this-\>Auth-\>login to log them in with that data.

---

<div class="post-metadata">

**Author:** ![ADmad](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/admad/32/20_2.png) [@ADmad](https://discourse.cakephp.org/u/ADmad)\
**Post date:** [October 3, 2018, 8:15am UTC](https://discourse.cakephp.org/t/multiple-authentication-methods-form-and-jwt/5005/3 "2018-10-03T08:15:21Z")

</div>

Don’t mix stateful and stateless auths. Use `Form` authenticator only for your webapp.

For SPA use a separate route prefix `api` for example and configure JWT auth only for that prefix. You can have separate `AppController` for the `api` prefix and configure `Auth` component for it with just JWT authenticator. Read the tutorial linked in my plugins’ readme.
