Skip to content

Unauthorized error for getting session #166

@yunsun330

Description

@yunsun330

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething is not working.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions