# Different behaviour on second login

**URL:** <https://community.auth0.com/t/different-behaviour-on-second-login/7887>\
**Category:** Get Help\
**Tags:** first-login-jwt-as-i, second-login-jwt-as-\
**Created:** [August 18, 2017, 1:45pm UTC](https://community.auth0.com/t/different-behaviour-on-second-login/7887 "2017-08-18T13:45:08Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![yzolotarev](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/yzolotarev/32/7888_2.png) [@yzolotarev](https://community.auth0.com/u/yzolotarev)\
**Post date:** [August 18, 2017, 1:45pm UTC](https://community.auth0.com/t/different-behaviour-on-second-login/7887/1 "2017-08-18T13:45:08Z")

</div>

Hello, I have this issue and I’m not sure whether it is a “bug” or my fault somewhere. Will be really glad if you can help me clarify and may be suggest some reading.  
I have updated my hosted page Auth0lock object to inculde a params object with a specified audience  
params: {  
“audience”: “[https://api.webatom.com](https://api.webatom.com)”  
}  
During the first login I get the usual auth result where I receive the JWT as the id\_token and a short string for the access token and I don’t get a message in auth0 about account access request.  
During the second and other logins I get what I want. I get the message and I get the JWT as access token and id\_token as null.  
How do I get that second result from the start, right from the first login? Is that a bug or am I doing something wrong?  
Thank you.  
PS: I don’t have any rules or hooks implemented at that moment.

---

<div class="post-metadata">

**Author:** ![jmangelo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jmangelo/32/7923_2.png) [@jmangelo](https://community.auth0.com/u/jmangelo)\
**Post date:** [August 18, 2017, 2:56pm UTC](https://community.auth0.com/t/different-behaviour-on-second-login/7887/2 "2017-08-18T14:56:46Z")

</div>

There are a few things worth noting here. Technically, at this time, Lock does not formally support an `audience` parameter. There is indeed some _support_ at the library level, but this is not yet documented and it’s not a final version so you should not be using it.

In addition, the future support for `audience` in the Lock library is meant for the use cases where you’re using it within your own client application. If your usage of Lock is within the hosted login page then you should not have to configure this parameter. If your intentions are to always use a given audience without having to specify it in each request then you should use the _Default Audience_ settings available in your account _General_ settings. Have in mind that setting this option is a global change so it may impose breaking changes on some client application; if you’re just starting your implementation then setting this should be fine.

In conclusion, what you’re doing is not supported; you should be providing the audience when you redirect to the hosted login page and not within the page itself. If you have a SPA application this would generally be done by proper configuration of Auth0.js which is likely the library you use to redirect to the hosted page.

---

<div class="post-metadata">

**Author:** ![yzolotarev](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/yzolotarev/32/7888_2.png) [@yzolotarev](https://community.auth0.com/u/yzolotarev)\
**Post date:** [August 21, 2017, 8:08pm UTC](https://community.auth0.com/t/different-behaviour-on-second-login/7887/3 "2017-08-21T20:08:58Z")

</div>

Setting the global audience didn’t help, still get an opaque access token on the first login and a proper jwt one only on the second and onwards

I guess I could live without the audience but I’m using the angular2-jwt library which attaches the authentication header into the requests. The header is then decoded in my [ASP.NET](http://ASP.NET) Core part and I can successfully use the [Authirize] annotation to block my api’s from direct access. If I stick an opaque\_token in the header (withput the audience) the [ASP.NET](http://ASP.NET) Core part fails when reading the header and says that audience don’t match which is true.

---

<div class="post-metadata">

**Author:** ![yzolotarev](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/yzolotarev/32/7888_2.png) [@yzolotarev](https://community.auth0.com/u/yzolotarev)\
**Post date:** [August 21, 2017, 9:50pm UTC](https://community.auth0.com/t/different-behaviour-on-second-login/7887/4 "2017-08-21T21:50:20Z")

</div>

To be more precise that is what I get if I try the opaque mode and have the [Authorize] annotation set on my API  
WWW-Authenticate:Bearer error=“invalid\_token”, error\_description=“The audience is invalid”, however now I realize that there is the aud: parameter inside the payload and I don’t understand why can’t ASP decode it…

---

<div class="post-metadata">

**Author:** ![yzolotarev](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/yzolotarev/32/7888_2.png) [@yzolotarev](https://community.auth0.com/u/yzolotarev)\
**Post date:** [August 21, 2017, 10:45pm UTC](https://community.auth0.com/t/different-behaviour-on-second-login/7887/5 "2017-08-21T22:45:01Z")

</div>

So far I have found an interesting work around…  
When an opaque token is returned, you can simply copy its aud hash and paste it into the Audience paramenter when creating the JwtBearerOptions object int the startup class. That fixes the error with the invalid audience when using the [Authorize] annotation in the controller api.

---

<div class="post-metadata">

**Author:** ![yzolotarev](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/yzolotarev/32/7888_2.png) [@yzolotarev](https://community.auth0.com/u/yzolotarev)\
**Post date:** [August 21, 2017, 8:08pm UTC](https://community.auth0.com/t/different-behaviour-on-second-login/7887/6 "2017-08-21T20:08:58Z")

</div>

Setting the global audience didn’t help, still get an opaque access token on the first login and a proper jwt one only on the second and onwards

I guess I could live without the audience but I’m using the angular2-jwt library which attaches the authentication header into the requests. The header is then decoded in my [ASP.NET](http://ASP.NET) Core part and I can successfully use the [Authirize] annotation to block my api’s from direct access. If I stick an opaque\_token in the header (withput the audience) the [ASP.NET](http://ASP.NET) Core part fails when reading the header and says that audience don’t match which is true.

---

<div class="post-metadata">

**Author:** ![yzolotarev](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/yzolotarev/32/7888_2.png) [@yzolotarev](https://community.auth0.com/u/yzolotarev)\
**Post date:** [August 21, 2017, 9:50pm UTC](https://community.auth0.com/t/different-behaviour-on-second-login/7887/7 "2017-08-21T21:50:20Z")

</div>

To be more precise that is what I get if I try the opaque mode and have the [Authorize] annotation set on my API  
WWW-Authenticate:Bearer error=“invalid\_token”, error\_description=“The audience is invalid”, however now I realize that there is the aud: parameter inside the payload and I don’t understand why can’t ASP decode it…

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [March 2, 2018, 5:55am UTC](https://community.auth0.com/t/different-behaviour-on-second-login/7887/8 "2018-03-02T05:55:59Z")

</div>


