def token_reply_info(client, scope, user = nil, state = nil, refresh = false)
    interval = client[:access_token_validity] || 3600
    token_body = { jti: SecureRandom.uuid, aud: scope, scope: scope,
        client_id: client[:client_id], exp: interval + Time.now.to_i }
    if user
      token_body[:user_id] = user[:id]
      token_body[:email] = primary_email(user[:emails])
      token_body[:user_name] = user[:username]
    end
    info = { access_token: TokenCoder.encode(token_body, :algorithm => 'none'),
        token_type: 'bearer', expires_in: interval, scope: scope}
    info[:state] = state if state
    info[:refresh_token] = 'universal_refresh_token' if refresh
    inject_error(info)
    info
  end
def token_reply_info(client, scope, user = nil, state = nil, refresh = false)
    interval = client[:access_token_validity] || 3600
    token_body = { jti: SecureRandom.uuid, aud: scope, scope: scope,
        client_id: client[:client_id], exp: interval + Time.now.to_i }
    if user
      token_body[:user_id] = user[:id]
      token_body[:email] = primary_email(user[:emails])
      token_body[:user_name] = user[:username]
    end
    info = { access_token: TokenCoder.encode(token_body, :algorithm => 'none'),
        token_type: 'bearer', expires_in: interval, scope: scope}
    info[:state] = state if state
    info[:refresh_token] = 'universal_refresh_token' if refresh
    inject_error(info)
    info
  end
----------------------------------------------------------------------------
 oauth2 endpoints and helpers

 current uaa token contents: exp, user_name, scope, email, user_id,
    client_id, client_authorities, user_authorities