module BookingsyncApplication::Controllers::BookingsyncUniverseApiAccess

Private Instance Methods

auth_path() click to toggle source
# File lib/bookingsync_application/controllers/bookingsync_universe_api_access.rb, line 28
def auth_path
  "/api/v3/auth"
end
authenticate_account!() click to toggle source
Calls superclass method
# File lib/bookingsync_application/controllers/bookingsync_universe_api_access.rb, line 6
def authenticate_account!
  if auth = request.headers["Authorization"].presence
    response = Faraday.new(url: bookingsync_url).get do |req|
      req.url auth_path
      req.headers["Authorization"] = auth
    end
    if response.success?
      @scope = AuthorizationScope.from_response(response)

      session[:account_id] = scope.account_id
    else
      render json: response.body, status: response.status and return
    end
  else
    super
  end
end
bookingsync_universe_authorize_request!(*required_scopes) click to toggle source
# File lib/bookingsync_application/controllers/bookingsync_universe_api_access.rb, line 36
def bookingsync_universe_authorize_request!(*required_scopes)
  if !scope.allows_access_for?(Array(required_scopes).map(&:to_s))
    render json: { errors: [ { code: :forbidden } ] }, status: 403 and return
  end
end
bookingsync_url() click to toggle source
# File lib/bookingsync_application/controllers/bookingsync_universe_api_access.rb, line 24
def bookingsync_url
  "#{ENV['BOOKINGSYNC_URL']}"
end
scope() click to toggle source
# File lib/bookingsync_application/controllers/bookingsync_universe_api_access.rb, line 32
def scope
  @scope
end