# Can you give a sample log in program using JWT?

**URL:** <https://community.auth0.com/t/can-you-give-a-sample-log-in-program-using-jwt/9543>\
**Category:** Get Help\
**Tags:** log-in, sample-project, sample, jwt\
**Created:** [February 20, 2018, 8:16pm UTC](https://community.auth0.com/t/can-you-give-a-sample-log-in-program-using-jwt/9543 "2018-02-20T20:16:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pilipinass123](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@pilipinass123](https://community.auth0.com/u/pilipinass123)\
**Post date:** [February 20, 2018, 8:16pm UTC](https://community.auth0.com/t/can-you-give-a-sample-log-in-program-using-jwt/9543/1 "2018-02-20T20:16:52Z")

</div>

i’m having a trouble understanding JWT. can you help me?

---

<div class="post-metadata">

**Author:** ![jerdog](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jerdog/32/11231_2.png) [@jerdog](https://community.auth0.com/u/jerdog)\
**Post date:** [February 21, 2018, 12:22am UTC](https://community.auth0.com/t/can-you-give-a-sample-log-in-program-using-jwt/9543/2 "2018-02-21T00:22:40Z")

</div>

Sure @pilipinass123 - there are a few good resources for getting started with JWT:

- [Get Started with JSON Web Tokens](https://auth0.com/learn/json-web-tokens/)
- Similar content to the above - [JSON Web Tokens](https://auth0.com/docs/jwt)
- [JWT eBook](https://auth0.com/e-books/jwt-handbook)
- [Auth0 Quickstarts](https://auth0.com/docs/quickstarts)

---

<div class="post-metadata">

**Author:** ![ricardo.batista](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ricardo.batista/32/7711_2.png) [@ricardo.batista](https://community.auth0.com/u/ricardo.batista)\
**Post date:** [February 21, 2018, 12:35am UTC](https://community.auth0.com/t/can-you-give-a-sample-log-in-program-using-jwt/9543/3 "2018-02-21T00:35:29Z")

</div>

A [JWT] ([RFC 7519: JSON Web Token (JWT)](https://tools.ietf.org/html/rfc7519)) defines a way to transfer data between two parties. It consists of three parts separated by dots (.), which are:

- Header
- Payload
- Signature

Therefore it typically looks like: `xxxxx.yyyyy.zzzzz` You can use [https://jwt.io/](https://jwt.io/) to decode it and see the claims it contains.

To get an [id token](https://auth0.com/docs/tokens/id-token) or an [access token] ([Access Tokens](https://auth0.com/docs/tokens/access-token)) you can use [Auth0.js](https://github.com/auth0/auth0.js), [Lock.js](https://auth0.com/docs/libraries/lock/v11), [the Authentication API] ([https://auth0.com/docs/api/authentication](https://auth0.com/docs/api/authentication)) or any other library for another language. A common use would be to use the [hosted login page] ([Auth0 Universal Login](https://auth0.com/docs/hosted-pages/login)) with Auth0.js and a SPA client as:

```
<script src="http://cdn.auth0.com/js/auth0/9.1.0/auth0.min.js"></script>
<script>
var webAuth = new auth0.WebAuth({
  domain: {YOUR_AUTH0_DOMAIN}, 
  clientID: {SPA_CLIENT_ID},
  audience: {API_AUDIENCE},
  redirectUri: '{CALLBACK_URL}', 
  scope: 'openid profile',
  responseType: 'token id_token'
});
webAuth.authorize();
</script>

```

On the callback from the authorize request, you can use parseHash to get the JWT tokens:

```
webAuth.parseHash(function(err, authResult) {
  if (authResult) {
    var accessToken = authResult.accessToken;
    var idToken = authResult.idToken;

     // any other logic...
  }
}

```

You can see more detailed information about JWTs [here] ([JSON Web Tokens](https://auth0.com/docs/jwt)) and you should also check [OIDC conformant clients] ([Applications in Auth0](https://auth0.com/docs/api-auth/tutorials/adoption/oidc-conformant)), [OIDC authentication] ([OpenID Connect Protocol](https://auth0.com/docs/api-auth/tutorials/adoption)) and [how to call your APIs with the access token] ([Access Tokens](https://auth0.com/docs/api-auth/tutorials/adoption/api-tokens))

---

<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:** [August 27, 2019, 10:37am UTC](https://community.auth0.com/t/can-you-give-a-sample-log-in-program-using-jwt/9543/4 "2019-08-27T10:37:32Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
