Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customize the JWT payload #80

Merged
merged 5 commits into from Mar 1, 2016

Conversation

Projects
None yet
2 participants
@enten
Copy link
Contributor

enten commented Feb 24, 2016

PR to implements JWT payload customization #78

Add a new option extraFields which requires an array of field names (corresponding to the fields of the userEndpoint service).

Usage

// default.json
{
  "auth": {
    "extraFields": [
      "email",
      "roles"
    ]
  }
}

// create token
// $ curl http://localhost:3030/auth/local
//      -X POST
//      -H 'Accept: application/json' 
//      -H 'Content-type: application/json' 
//      -d '{"email": "steven@enten.fr", "password":"pass"}'
{
  "email": "steven@enten.fr",
  "roles": [
    "admin"
  ],
  "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IjUyYjEzNDUwLTRjMzEtNDA4Yi04OWU5LWMxMzkxYTk1N2Q5MiIsImVtYWlsIjoic3RldmVuQGVudGVuLmZyIiwicm9sZXMiOlsiYWRtaW4iXSwiaWF0IjoxNDU2MzkxMTUzLCJleHAiOjE0NTY0Nzc1NTMsImlzcyI6ImZlYXRoZXJzIn0.VWUOUS4wjGDiQ4wXYyiQfxt8YOaSD6kWB6je-OpAneo",
  "data": {
    "id": "52b13450-4c31-408b-89e9-c1391a957d92",
    "email": "steven@enten.fr",
    "roles": [
      "admin"
    ],
    "profile": {
      "foo": "bar"
    },
    "activated": false,
    "activation_token": "IgaifUlghYXQ",
    "created_at": "2016-02-24T23:19:34.158Z",
    "updated_at": "2016-02-24T23:20:43.337Z",
    "deleted_at": null
  }
}

// decrypted token
{
  "id": "52b13450-4c31-408b-89e9-c1391a957d92",
  "email": "steven@enten.fr",
  "roles": [
    "admin"
  ],
  "iat": 1456391153,
  "exp": 1456477553,
  "iss": "feathers"
}

// refresh token
// $ curl http://localhost:3030/auth/token/refresh
//      -X GET
//      -H 'Accept: application/json'
//      -H 'Content-type: application/json'
//      -H'Authorization: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IjUyYjEzNDUwLTRjMzEtNDA4Yi04OWU5LWMxMzkxYTk1N2Q5MiIsImVtYWlsIjoic3RldmVuQGVudGVuLmZyIiwicm9sZXMiOlsiYWRtaW4iXSwiaWF0IjoxNDU2MzkxMTUzLCJleHAiOjE0NTY0Nzc1NTMsImlzcyI6ImZlYXRoZXJzIn0.VWUOUS4wjGDiQ4wXYyiQfxt8YOaSD6kWB6je-OpAneo'
{
  "email": "steven@enten.fr",
  "roles": [
    "admin"
  ],
  "iat": 1456391153,
  "exp": 1456477553,
  "iss": "feathers",
  "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IjUyYjEzNDUwLTRjMzEtNDA4Yi04OWU5LWMxMzkxYTk1N2Q5MiIsImVtYWlsIjoic3RldmVuQGVudGVuLmZyIiwicm9sZXMiOlsiYWRtaW4iXSwiaWF0IjoxNDU2MzkxMTUzLCJleHAiOjE0NTY0Nzc3NzAsImlzcyI6ImZlYXRoZXJzIn0.838omN2kACyWU5uR-NSjfMfjtXFxAV1V8ol48IRgRIQ",
  "data": {
    "id": "52b13450-4c31-408b-89e9-c1391a957d92",
    "email": "steven@enten.fr",
    "roles": [
      "admin"
    ],
    "profile": {
      "foo": "bar"
    },
    "activated": false,
    "activation_token": "IgaifUlghYXQ",
    "created_at": "2016-02-24T23:19:34.158Z",
    "updated_at": "2016-02-24T23:20:43.337Z",
    "deleted_at": null
  }
}

// decrypted token
{
  "id": "52b13450-4c31-408b-89e9-c1391a957d92",
  "email": "steven@enten.fr",
  "roles": [
    "admin"
  ],
  "iat": 1456391153,
  "exp": 1456477770,
  "iss": "feathers"
}






@ekryski

This comment has been minimized.

Copy link
Member

ekryski commented Feb 28, 2016

@enten I haven't forgotten about this. We've just been super busy. Will get to it in a couple days.

@ekryski

This comment has been minimized.

Copy link
Member

ekryski commented Feb 29, 2016

@enten sorry about this but do you mind resolving the merge conflicts? This looks good and I'm writing tests today. When you do I'll merge it in right away and hopefully get a release out by tomorrow.

@enten

This comment has been minimized.

Copy link
Contributor Author

enten commented Mar 1, 2016

The conflict was in README.md.

@ekryski

This comment has been minimized.

Copy link
Member

ekryski commented Mar 1, 2016

Whoop! Thanks!

ekryski added a commit that referenced this pull request Mar 1, 2016

Merge pull request #80 from enten/master
Customize the JWT payload

@ekryski ekryski merged commit 21eca79 into feathersjs:master Mar 1, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@enten

This comment has been minimized.

Copy link
Contributor Author

enten commented Mar 1, 2016

Sorry. I made a mistake in README changelog.

You need to remove <<<<<<< HEAD line.

@ekryski

This comment has been minimized.

Copy link
Member

ekryski commented Mar 1, 2016

No problemo! Fixed it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.