private ResourceResponse getResourceResponse(
      Context context, String clientId, Iterable<JsonValue> tokens)
      throws NotFoundException, InvalidClientException, ServerException,
          InternalServerErrorException {
    String realm = getAttributeValue(tokens.iterator().next(), REALM.getOAuthField());
    OAuth2ProviderSettings oAuth2ProviderSettings = oAuth2ProviderSettingsFactory.get(context);

    ClientRegistration clientRegistration = clientRegistrationStore.get(clientId, realm, context);
    Map<String, String> scopeDescriptions =
        clientRegistration.getScopeDescriptions(getLocale(context));
    Map<String, String> scopes = new HashMap<>();
    for (JsonValue token : tokens) {
      for (String scope : token.get(SCOPE.getOAuthField()).asSet(String.class)) {
        if (scopeDescriptions.containsKey(scope)) {
          scopes.put(scope, scopeDescriptions.get(scope));
        } else {
          scopes.put(scope, scope);
        }
      }
    }

    String displayName = clientRegistration.getDisplayName(getLocale(context));
    String expiryDateTime = calculateExpiryDateTime(tokens, oAuth2ProviderSettings);

    JsonValue content =
        json(
            object(
                field("_id", clientId),
                field("name", displayName),
                field("scopes", scopes),
                field("expiryDateTime", expiryDateTime)));

    return Responses.newResourceResponse(
        clientId, String.valueOf(content.getObject().hashCode()), content);
  }
 /** {@inheritDoc} */
 public Set<String> validateRefreshTokenScope(
     ClientRegistration clientRegistration,
     Set<String> requestedScope,
     Set<String> tokenScope,
     OAuth2Request request)
     throws ServerException, InvalidScopeException {
   return scopeValidator.scopeRequestedForRefreshToken(
       requestedScope,
       clientRegistration.getAllowedScopes(),
       tokenScope,
       clientRegistration.getDefaultScopes());
 }
 /** {@inheritDoc} */
 public Set<String> validateAuthorizationScope(
     ClientRegistration clientRegistration, Set<String> scope, OAuth2Request request)
     throws ServerException, InvalidScopeException {
   return scopeValidator.scopeToPresentOnAuthorizationPage(
       scope, clientRegistration.getAllowedScopes(), clientRegistration.getDefaultScopes());
 }