Hi, I’m failing to get the cookie or session from ...
# ory-network
a
Hi, I’m failing to get the cookie or session from Ory Network after sign in using the SDK’s FrontEnd API. See attached video
Copy code
# config/initializers/ory_client.rb
OryClient.configure do |config|
  config.access_token = 'YOUR_BEARER_TOKEN'
  config.api_key = {}
  config.api_key_prefix
  # config.base_path = "<http://localhost:5200>"
  config.cert_file = nil
  config.client_side_validation = false
  config.debugging = false
  config.force_ending_format = false
  config.host = "<https://SLUG.projects.oryapis.com>"
  config.inject_format = false
  config.key_file = nil
  config.logger = ActiveSupport::Logger #‹ActiveSupport::Logger:0x0000000107c4ebb0>
  config.params_encoding = nil
  config.scheme = "https"
  config.server_index = nil # see this issue: <https://github.com/ory/kratos-client-ruby/issues/3#issuecomment-955609406>
  config.server_operation_index = {}
  config.server_operation_variables = {}
  config.server_variables = {}
  config.timeout = 0
  config.verify_ssl = false
  config.verify_ssl_host = false
end

# app/controllers/auth_controller.rb
class ApplicationController < ActionController::Base
  before_action :ory_client

  def ory_client
    @_ory_client ||= OryClient::FrontendApi.new
  end
end

# app/controllers/auth_controller.rb
class AuthController < ApplicationController

  def login
    redirect_to login_flow_url, allow_other_host: true
  end

  private
  def login_flow_url
    res = ory_client.create_browser_login_flow
    res.ui.action
  end
end

# app/controllers/callback_controller.rb
class CallbackController < ApplicationController
  def index
    cookies # <ActionDispatch::Cookies::CookieJar:0x000000011566fec0 @set_cookies={}, @delete_cookies={}, @request=#<ActionDispatch::Request GET \"<http://localhost:3000/auth/callback>\" for 127.0.0.1>, @cookies={\"_poc1_sc1_app1_session\"=>\"12StaGYYebeaIrtRs5djlrGSuQzLEsMHbWOPjgCSNQmdcayikSU4J6C2aWmrzAZhXX1mfOIeeDTH5vLIyvPp6lw6XAMP9B7sqXdJquhac7Ndx7tJCS0gHaUjbJjMa14AK5FuW3QcSzZHMlhDl5vLFx5YSAHmi1vlzWkU1zVyA+Mr2io3s0zuAICX4eZhyTth7ftC064Qw+UdDLwmLEnbZzc93JOLIxhS5rnBUUi2qEZAGT/+Oczp+ZI335S9rVSm8A2hk5yflxQbIT5ZNTRSqZKqQqk3dgM+gL5Eiff9--qHcaT6bYkC9QtCzT--2AbFwmOTOfDQjWy3jmT+sQ==\"}, @committed=false>"

    headers  # {"X-Frame-Options"=>"SAMEORIGIN", "X-XSS-Protection"=>"0", "X-Content-Type-Options"=>"nosniff", "X-Download-Options"=>"noopen", "X-Permitted-Cross-Domain-Policies"=>"none", "Referrer-Policy"=>"strict-origin-when-cross-origin"}

    session #<ActionDispatch::Request::Session:0xc670 not yet loaded>

    # ory_client.to_session

    redirect_to root_path
  end
end
p
Hi @agreeable-lifeguard-99976 Please ensure you are routing the request through the Ory tunnel. https://www.ory.sh/docs/getting-started/local-development. Your application i see is calling the project directly (redirecting to https://project-slub.ory...)
In local development the browser is on the "localhost" domain which is different from <project-slug>.projects.oryapis.com.
That is why you need the Ory Cli tunnel. When deploying this to production, please add a custom domain to the project as shown here https://www.ory.sh/docs/guides/custom-domains
a
I do have the proxy tunnel. Need figure out what I’m doing wrong.
p
just point your UI (where you click login) to the tunnel
<http://localhost:4000>
take note of the URL in the browser. It should show you the account experience under
<https://localhost:4000/ui/login>
a
My ory proxy
So I don’t reach the account experience under
<https://localhost:4000/ui/login>
Ah silly me I’m running proxy and UI need tunnel 🤦
Thanks @proud-plumber-24205
p
it's no problem, you can also use the proxy, but the url will then be served under the
/.ory/
path. For example, you are running the proxy under
<http://localhost:3000>
and your application is under
<http://localhost:4000>
then Ory will live under
<http://localhost:3000/.ory/ui/login>
. So in the UI you would need to point to
<http://localhost:3000/.ory>
I generally recommend using the Ory CLI tunnel since it is a "sidecar" to the UI, leaving the UI to be accessed directly by the browser instead of "through" the proxy. I think the documentation here still uses the Ory proxy as an example, which I think we should update 😅
🙌 1