# Getting properties from a custom database connection

**URL:** <https://community.auth0.com/t/getting-properties-from-a-custom-database-connection/10469>\
**Category:** JWT.io\
**Tags:** custom-database\
**Created:** [March 28, 2018, 7:44pm UTC](https://community.auth0.com/t/getting-properties-from-a-custom-database-connection/10469 "2018-03-28T19:44:39Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![craigsch](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@craigsch](https://community.auth0.com/u/craigsch)\
**Post date:** [March 28, 2018, 7:44pm UTC](https://community.auth0.com/t/getting-properties-from-a-custom-database-connection/10469/1 "2018-03-28T19:44:40Z")

</div>

I am just starting to work with Auth0 and SSO so forgive the probably simply question. I have successfully created a custom connection to our API so that I can have my SPA app authenticate through it and retrieve key user information.

I can successfully authenticate and get both the access\_token and id\_token back. But I cannot seem to retrieve the properties I returned back from my custom connection to my API. I have used various scopes “openid email profile” but I still do not get back this information. I used the [JWT.IO](http://JWT.IO) debugger and decode both tokens and still don’t see it. Is this information located in the last section of the JWT token? And if so where I can get the key used to decode this information.

Thanks for any help

---

<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:** [March 29, 2018, 12:46pm UTC](https://community.auth0.com/t/getting-properties-from-a-custom-database-connection/10469/2 "2018-03-29T12:46:28Z")

</div>

Is it possible to use `console log` statements in the script in order to see what’s happening? Also your connection script would be helpful, making sure to remove any sensitive info

---

<div class="post-metadata">

**Author:** ![craigsch](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@craigsch](https://community.auth0.com/u/craigsch)\
**Post date:** [March 29, 2018, 1:34pm UTC](https://community.auth0.com/t/getting-properties-from-a-custom-database-connection/10469/3 "2018-03-29T13:34:08Z")

</div>

It seems when I test it I do get back the info I was looking for in my profile. I just don’t know how that gets added to my tokens as I do not see it. Any way here is the script. I simply calls an existing API call with username&password.

=====================

```
function login (email, password, callback) {

  var emailPassword = email + ":" + password;
  var emailPasswordBase64 = new Buffer( emailPassword, "utf8" ).toString("base64");
  var authString = "Basic " + emailPasswordBase64;
  
  request.get({
    url: configuration.QA + "/v1/users/info?email=" + email,
    headers: {
    authorization: authString
    }
    //for more options check:
    //https://github.com/mikeal/request#requestoptions-callback
  }, function (err, response, body) {
    
    if (err) return callback(err);
    if (response.statusCode === 401) return callback();
    var user = JSON.parse(body);

    callback(null, {
      id: user.id,
      email: email,
      currentTenantId: user.currentTenantId,
      currentOrgNumber: user.currentOrgNumber,
      currentOrgName: user.currentOrgName,
      currentOrgRole: user.currentOrgRole,
      currentOrgType: user.currentOrgType,
      culture: user.culture,
    });

  });

}

```

---

<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:** [April 3, 2018, 1:09pm UTC](https://community.auth0.com/t/getting-properties-from-a-custom-database-connection/10469/4 "2018-04-03T13:09:16Z")

</div>

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

---

<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:** [April 3, 2018, 1:23pm UTC](https://community.auth0.com/t/getting-properties-from-a-custom-database-connection/10469/5 "2018-04-03T13:23:44Z")

</div>



---

<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:** [April 3, 2018, 1:24pm UTC](https://community.auth0.com/t/getting-properties-from-a-custom-database-connection/10469/7 "2018-04-03T13:24:57Z")

</div>

@craigsch let me review and we’ll get back to you

---

<div class="post-metadata">

**Author:** ![craigsch](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@craigsch](https://community.auth0.com/u/craigsch)\
**Post date:** [April 3, 2018, 4:47pm UTC](https://community.auth0.com/t/getting-properties-from-a-custom-database-connection/10469/8 "2018-04-03T16:47:58Z")

</div>

I made the assumption that these properties would automatically come back in the id\_token. It seems not to be the case. With some experimentation I wrote a rule that included the user object in a namespace. It then came back and now I see the data once I decode the token. The documentation does not call that out at all. Hopefully this is the accepted way to retrieve this information at authentication time. Let me know if I am correct that I have to write a rule for this.

---

<div class="post-metadata">

**Author:** ![kimcodes](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/kimcodes/32/81052_2.png) [@kimcodes](https://community.auth0.com/u/kimcodes)\
**Post date:** [April 5, 2018, 7:12pm UTC](https://community.auth0.com/t/getting-properties-from-a-custom-database-connection/10469/9 "2018-04-05T19:12:38Z")

</div>

👋 @craig jumping in here, yes you can add custom claims to your `id_token` via a [Rule](https://auth0.com/docs/rules/current) ([OpenID Connect Scopes](https://auth0.com/docs/api-auth/tutorials/adoption/scope-custom-claims#custom-claims)) . Please let me know if this is what you are referring to!

---

<div class="post-metadata">

**Author:** ![craigsch](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@craigsch](https://community.auth0.com/u/craigsch)\
**Post date:** [April 5, 2018, 7:52pm UTC](https://community.auth0.com/t/getting-properties-from-a-custom-database-connection/10469/10 "2018-04-05T19:52:17Z")

</div>

Yes this is what I was referring to. So I was able to get information back to my SPA front end in the idToken but more importantly I needed a few key pieces in the Access token so that my WebApi would know the current user and role through the existing claims mechanism. It took me a little sleuthing but found that if I added this to the rule

```
 context.accessToken["http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name"] = user.email;
 context.accessToken["http://schemas.microsoft.com/ws/2008/06/identity/claims/role"] = user.currentOrgRole;
 context.accessToken["http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier"] = user._id;

```

I could use my existing principle claims code to get the current user, current role and current user id from the Access token. Those namespaces where key.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [December 17, 2018, 11:00am UTC](https://community.auth0.com/t/getting-properties-from-a-custom-database-connection/10469/11 "2018-12-17T11:00:13Z")

</div>


