# Jwt issue on Authentication

**URL:** <https://discourse.laminas.dev/t/jwt-issue-on-authentication/1410>\
**Category:** API Tools\
**Tags:** authentication, authorization\
**Created:** [March 4, 2020, 2:31am UTC](https://discourse.laminas.dev/t/jwt-issue-on-authentication/1410 "2020-03-04T02:31:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![juliangorge](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/juliangorge/32/608_2.png) [@juliangorge](https://discourse.laminas.dev/u/juliangorge)\
**Post date:** [March 4, 2020, 2:31am UTC](https://discourse.laminas.dev/t/jwt-issue-on-authentication/1410/1 "2020-03-04T02:31:48Z")

</div>

Hello there!  
I’m very confused since long days trying to implement Login User System with oAuth2 (no social), so I apologize for disturbing you but I see a little lost.

I’ve read and read every page on web to how use the access\_token and I’ve got no clear: Have I need an access\_token always in the Authorization header?.

When I use this, always I get “guest” user from $this-\>getIdentity()-\>getName()

 ![Captura de Pantalla 2020-03-03 a la(s) 22.55.47](https://canada1.discourse-cdn.com/flex032/uploads/zendframework/original/1X/fc2e28e7e5399bd6e24efe89d8ed89f0043a98f9.png)

On module.php

```
public function onAuthentication(MvcAuthEvent $e)
{
    $guest = new GuestIdentity();
    $header = $e->getMvcEvent()->getRequest()->getHeader('Authorization');

    if(!$header) return $guest;

    $token = $header->getFieldValue();
    $jwt = new Jwt();
    $key = $this->serviceManager->get('config')['cryptoKey'];
    $tokenData = $jwt->decode($token, $key);

```

tokenData is false, cryptoKey is like auth-doc so return to guess identity.

```
<?php
return [
    //Social login
    'cryptoKey' => 'SOME SUPER SECRET PASSPHRASE HERE THAT YOU JUST MADE UP',

```

I’m assumming that AuthenticatedIdentity() storage the session data, is it right?  
Thank you a lot.

---

<div class="post-metadata">

**Author:** ![Leafar\_Avlis](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/leafar_avlis/32/598_2.png) [@Leafar\_Avlis](https://discourse.laminas.dev/u/Leafar_Avlis)\
**Post date:** [March 5, 2020, 12:02am UTC](https://discourse.laminas.dev/t/jwt-issue-on-authentication/1410/2 "2020-03-05T00:02:13Z")

</div>

can you put all your code, include GuestIdentity. Whats package is this Jwt from?

---

<div class="post-metadata">

**Author:** ![juliangorge](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/juliangorge/32/608_2.png) [@juliangorge](https://discourse.laminas.dev/u/juliangorge)\
**Post date:** [March 5, 2020, 1:57am UTC](https://discourse.laminas.dev/t/jwt-issue-on-authentication/1410/4 "2020-03-05T01:57:48Z")

</div>

Thank you a lot for your answer.

> **[juliangorge/OAuth-Api-Tools](https://github.com/juliangorge/OAuth-Api-Tools)**
>
> Contribute to juliangorge/OAuth-Api-Tools development by creating an account on GitHub.
