Skip to Content Skip to Search
Methods
C
D
R
S
Included Modules

Constants

CLOCK_DRIFT_ALLOWANCE = 30
 

Instance Public methods

create()

# File engines/oauth/app/controllers/o_auth_provider/tokens_controller.rb, line 36
def create
  grant = DB::AuthorizationGrant.find_by(code: tokens_params[:code])
  validator = AccessTokenValidator.new(@client, grant, access_token_validator_params)

  if grant && validator.valid_authorization?
    issuer = AccessTokenIssuer.new(grant)
    issuer.grant_access_token
    render json: issuer.data
  else
    render json: validator.error_data, status: :bad_request
  end
end

destroy()

# File engines/oauth/app/controllers/o_auth_provider/tokens_controller.rb, line 64
def destroy
  token = DB::AuthorizationGrant.find(tokens_params[:id])
  site = DB::Site.find token.site_id
  client = DB::OAuthClientApp.find_client_by(client_id: token.client_id, site: current_site)
  if client.admin_scoped?
    authorize!(site, :show?)
  else
    authorize!(site, :member?)
  end
  token.destroy
  flash[:success] = "Your access grant has been removed."
  redirect_back fallback_location: "/"
end

refresh()

# File engines/oauth/app/controllers/o_auth_provider/tokens_controller.rb, line 49
def refresh
  grant = DB::AuthorizationGrant.find_by(
    refresh_token_digest: Digest::SHA256.hexdigest(tokens_params[:refresh_token])
  )
  validator = AccessTokenValidator.new(@client, grant, access_token_validator_params)

  if grant && validator.valid_refresh?
    issuer = AccessTokenIssuer.new(grant)
    issuer.grant_access_token(tokens_params[:refresh_token])
    render json: issuer.data
  else
    render json: validator.error_data, status: :bad_request
  end
end

show()

# File engines/oauth/app/controllers/o_auth_provider/tokens_controller.rb, line 17
def show
  if Util::SignedToken.valid?(bearer_token)
    jwt = Util::SignedToken.decode(bearer_token)
    @grant = DB::AuthorizationGrant.where(public_id: jwt["public_id"]).find { |grant|
      ActiveSupport::SecurityUtils.secure_compare(
        ::Digest::SHA256.hexdigest(bearer_token),
        grant.access_token_digest
      ) && grant.expires_at.to_i > cutoff
    }
  end
  if @grant && Util::SignedToken.valid?(bearer_token)
    # client = DB::OAuthClientApp.find_client_by(client_id: @grant.client_id, site: current_site)
    # authorize!(client, :member_on_plan?) unless client.admin_scoped?
    render json: {status: "ok"}
  else
    render json: {error: "invalid_request"}, status: :unauthorized
  end
end