ory / ory/sdk

Unauthorized error for getting session

Open
#166 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
PHP
Stars
178
Forks
96
Avg merge
6d 23h
Merged PRs (30d)
3

Description

Preflight checklist
Describe the bug

Hello. I have integrated Ory Cloud in Rails project with ory-client
I made proxy with ory cli and worked login and registration successfully
I created project and got SDK configuration on ORY console.
And set env variable ORY_SDK_URL with that on my local.
I am trying to check session via api_instance.to_session, but gets unauthorized error
This endpoint calls https://playground.projects.oryapis.com/ all the time.
Would you help me how to create instance for my project which I created on ory console?

I set configuration like this:

OryClient.configure do |config|
  config.access_token = 'Personal_Access_Token'
  config.host = 'My_Project_Url'
end

And

api_instance = OryClient::V0alpha2Api.new

    opts = {
      x_session_token: nil,
      cookie: request.env['HTTP_COOKIE']
    }

    begin
      # Check Who the Current HTTP Session Belongs To
      result = api_instance.to_session(opts)
      p result
    rescue OryClient::ApiError => e
      puts "Error when calling V0alpha2Api->to_session: #{e}"
    end

But got error
HTTP status code: 401
Response headers: {"Date"=>"Fri, 01 Apr 2022 09:54:29 GMT", "Content-Type"=>"application/json", "Content-Length"=>"186", "Connection"=>"keep-alive", "cache-control"=>"private, no-cache, no-store, must-revalidate", "vary"=>"Origin,Cookie", "CF-Cache-Status"=>"DYNAMIC", "Expect-CT"=>"max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\"", "Set-Cookie"=>"__cflb=0pg1RbZMZcQY6KwtZw8ZHrqdVBkfNrHJsczBvGfV; SameSite=None; Secure; path=/; expires=Fri, 01-Apr-22 10:54:29 GMT; HttpOnly", "Server"=>"cloudflare", "CF-RAY"=>"6f507192aa59f55d-SEA", "alt-svc"=>"h3=":443"; ma=86400, h3-29=":443"; ma=86400"}
Response body: {"error":{"code":401,"status":"Unauthorized","request":"9fd4c275-2ca9-98ca-b1a7-a205a5175aa9","reason":"No valid session cookie found.","message":"The request could not be authorized"}}
ETHON: performed EASY effective_url=https://playground.projects.oryapis.com/sessions/whoami response_code=401 return_code=ok total_time=0.75955
Error when calling V0alpha2Api->to_session_with_http_info: Error message: the server returns an error

Reproducing the bug

You can check on this link:
https://ory-community.slack.com/archives/C02MR4DEEGH/p1648814785876499

Relevant log output

No response

Relevant configuration

No response

Version

Ruby 2.6.5, Rails 5.6.5

On which operating system are you observing this issue?

No response

In which environment are you deploying?

No response

Additional Context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The report names OryClient.configure and OryClient::V0alpha2Api#to_session, but no repository file or test. Start by tracing how the Ruby SDK selects its host and sends the session cookie, then reproduce the request with the reported ORY_SDK_URL configuration. Done means requests target the configured Ory Cloud project rather than the playground and session lookup behaves as documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
rails, ruby
Domain
api, authentication
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.