Class: RubyNative::Auth::SessionsController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/ruby_native/auth/sessions_controller.rb

Instance Method Summary collapse

Instance Method Details

#showObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/ruby_native/auth/sessions_controller.rb', line 4

def show
  data = OAuthMiddleware.read_token(params[:token])

  unless data
    Rails.logger.debug { "[RubyNative] OAuth token exchange failed: invalid or expired token" }
    head :unauthorized
    return
  end

  # Prevent the session middleware from appending its own (empty)
  # session cookie, which would overwrite the authenticated one.
  request.session_options[:skip] = true

  if data[:cookies].present?
    response.headers["set-cookie"] = data[:cookies].join("\n")
  end

  Rails.logger.debug { "[RubyNative] OAuth token exchanged, redirecting to #{data[:redirect_url]}" }
  render json: {redirect_url: data[:redirect_url]}
end