title: How to add more data in access_token JWT
body: <p>I am trying to add new fields in JWT token which is actually <code>access_token</code> which is generated with <code>grant_type=password</code>. I want to add more fields if grant type is only <code>password</code>.</p>
  
  <p>If I implement a custom token enhancer, it adds new fields in the response body of oauth login api. But I only need those new fields inside <code>access_token</code> JWT.</p>
  
  <p>e.g.:</p>
  
  <p>when decoding <code>access_token</code>, Object should be from </p>
  
  <pre><code>{
    "user_name": "uuid",
    "scope": [
      "trust"
    ],
    "exp": 1522008499,
    "authorities": [
      "USER"
    ],
    "jti": "9d827f63-99ba-4fc1-a838-bc74331cf660",
    "client_id": "myClient"
  }
  </code></pre>
  
  <p>to</p>
  
  <pre><code>{
    "user_name": "uuid",
    "newField": [
      {
        "newFieldChild": "1",
      },
      {
        "newFieldChild": "2",
      }
    ],
    "scope": [
      "trust"
    ],
    "exp": 1522008499,
    "authorities": [
      "USER"
    ],
    "jti": "9d827f63-99ba-4fc1-a838-bc74331cf660",
    "client_id": "myClient"
  }
  </code></pre>
  
  <p>Implementing <code>CustomTokenEnhancer</code> adds <code>newField</code> list in the response body of login: </p>
  
  <pre><code>{
      "access_token": "jwt-access_token",
      "token_type": "bearer",
      "refresh_token": "jwt-refresh_token",
      "expires_in": 299999,
      "scope": "trust",
      "jti": "b23affb3-39d3-408a-bedb-132g6de15d7",
      "newField": [
        {
          "newFieldChild": "1",
        },
        {
          "newFieldChild": "2",
        }
      ]
  }
  </code></pre>
  
  <p><code>CustomTokenEnhancer</code>:</p>
  
  <pre><code>public class CustomTokenEnhancer implements TokenEnhancer {
      @Override
      public OAuth2AccessToken enhance(
              OAuth2AccessToken accessToken,
              OAuth2Authentication authentication) {
          Map&lt;String, Object&gt; additionalInfo = new HashMap&lt;&gt;();
          Map&lt;String, String&gt; newFields = ....;
          additionalInfo.put("newField", newFields);
          ((DefaultOAuth2AccessToken) accessToken).setAdditionalInformation(additionalInfo);
          return accessToken;
      }
  }
  </code></pre>
  
  <p>is it possible to modify <code>access_token</code> JWT if <code>grant_type</code> is <code>password</code>?</p>