title: Scopes vs Roles when accessing Resource Server with Keycloak as Authentication Server
body: <p>I am using Keycloak as Authorization Server and setting up SPA (Public Client) that will be connecting to a REST service (Bearer-Only client / Resource Server).</p>
  <p>As far as I understand, scopes are group of claims and claims are information about the subject (authenticated user).  Scopes are passed at authentication step to the authorization server so that it will prompt the user to permit/deny access to those claims (user data / actions).  In the case of third party client trying to access data from for example Facebook, scopes are permissions given by the user to the client to access user's data from Facebook.  In case of Slack scope are used to allow / deny certain permissions for the third party client to perform operations on behalf of the user.</p>
  <p>In my case where the resource server does not hold any user information but OAuth is used for authentication / authorization and will use the access token to get users group membership and possibly role to allow/deny access to the data on the resource server.<br />
  Correct me if I am wrong but scopes are used more for the user to allow third party client to access his/her information from OIDC provider, possibly get user information from the ID Token.  On the other hand Roles / Groups that is set in the access token would be used to authorize the user to get data from the the resource server</p>
  <p>For example here is the<br />
  Access Token:</p>
  <pre><code>{
    &quot;exp&quot;: 1612294865,
    &quot;iat&quot;: 1612294565,
    &quot;auth_time&quot;: 1612294524,
    &quot;jti&quot;: &quot;e6c12a30-1b54-410a-81ba-ffe947dcebc9&quot;,
    &quot;iss&quot;: &quot;http://localhost:8080/auth/realms/demo&quot;,
    &quot;aud&quot;: &quot;rest-service&quot;,
    &quot;sub&quot;: &quot;e49f2e27-4b47-492e-a714-2497d4f669f8&quot;,
    &quot;typ&quot;: &quot;Bearer&quot;,
    &quot;azp&quot;: &quot;js-console&quot;,
    &quot;nonce&quot;: &quot;58faa6b8-a628-4b5a-8f0a-b33643812ef2&quot;,
    &quot;session_state&quot;: &quot;2470b7b4-1587-43d5-8747-911b01398c3d&quot;,
    &quot;acr&quot;: &quot;0&quot;,
    &quot;allowed-origins&quot;: [
      &quot;http://localhost:8000&quot;
    ],
    &quot;resource_access&quot;: {
      &quot;rest-service&quot;: {
        &quot;roles&quot;: [
          &quot;user&quot;
        ]
      }
    },
    &quot;scope&quot;: &quot;openid email profile&quot;,
    &quot;email_verified&quot;: false,
    &quot;preferred_username&quot;: &quot;test&quot;,
    &quot;group&quot;: [
      &quot;/my-group&quot;
    ]
  }
  </code></pre>
  <p>ID Token</p>
  <pre><code>{
    &quot;exp&quot;: 1612294865,
    &quot;iat&quot;: 1612294565,
    &quot;auth_time&quot;: 1612294524,
    &quot;jti&quot;: &quot;c3242eb4-9047-4913-9ac6-be3b4e2b5745&quot;,
    &quot;iss&quot;: &quot;http://localhost:8080/auth/realms/demo&quot;,
    &quot;aud&quot;: &quot;js-console&quot;,
    &quot;sub&quot;: &quot;e49f2e27-4b47-492e-a714-2497d4f669f8&quot;,
    &quot;typ&quot;: &quot;ID&quot;,
    &quot;azp&quot;: &quot;js-console&quot;,
    &quot;nonce&quot;: &quot;58faa6b8-a628-4b5a-8f0a-b33643812ef2&quot;,
    &quot;session_state&quot;: &quot;2470b7b4-1587-43d5-8747-911b01398c3d&quot;,
    &quot;at_hash&quot;: &quot;5hOJUzWD9H2DOuYCEnc6fQ&quot;,
    &quot;acr&quot;: &quot;0&quot;,
    &quot;email_verified&quot;: false,
    &quot;preferred_username&quot;: &quot;test&quot;
  }
  </code></pre>
  <p>The audience(aud) for the ID token is set to the Client (js-console) and returns just some user information and really only needs openid scope.  The access token aud is set to the rest service that will consume the access token and retrieve the roles and group information.</p>
  <p>This is a different usage of OAuth which in this case the user doesn't need to consent to anything but will authenticate and use the access token to get information based on the group membership.</p>
  <p>Is my understanding is correct?</p>
  <p>Thanks!</p>