Hello. I have integrated Ory Cloud in Rails projec...
# ory-network
f
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 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? https://github.com/ory/sdk/blob/master/clients/client/ruby/docs/V0alpha2Api.md#to_session
d
Hello. I think that you need to configure servers properly
f
Thanks for your reply I created project and got SDK configuration And set env variable ORY_SDK_URL with that
What else do I need to do?
https://github.com/ory/sdk/blob/master/clients/client/python/docs/V0alpha2Api.md#to_session there’s an example of Python SDK of how to setup project URL
I think that
Copy code
OryClient.configure do |config|
  config.host = 'your_project_url'
end
might help
f
Copy code
OryClient.configure do |config|
  config.access_token = 'Personal_Access_Token'
  config.host = 'My_Project_Url'
end
I tried already, but didn't get result HTTP status code: 401 Response headers: {"Date"=>"Fri, 01 Apr 2022 095429 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 105429 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
Do you have anything updated @User cc: @User ? I am waiting for you
d
Hello. My ruby crashes due to segfault. But I can share a working example toSession call in Python
You can have 401 Unauthenticated error because you pass wrong cookie. You need to pass is using
ory_session_projectidwithouthypens
f
How can I get the cookie?
d
request.cookies
they’re stored there
Here’s working sample for python
Copy code
import time
import ory_client
from ory_client.api import v0alpha2_api
from ory_client.model.json_error import JsonError
from ory_client.model.session import Session
from pprint import pprint
# Defining the host is optional and defaults to <https://playground.projects.oryapis.com>
# See configuration.py for a list of all supported configuration parameters.
configuration = ory_client.Configuration.get_default_copy()
configuration.host = "<https://auth.gen1us2k.com>"


# Enter a context with an instance of the API client
cookie ="ory_session_lovingturinguo2cv9nlhi=value=="
with ory_client.ApiClient(configuration) as api_client:
    # Create an instance of the API class
    api_instance = v0alpha2_api.V0alpha2Api(api_client)

    # example passing only required values which don't have defaults set
    # and optional values
    try:
        # Check Who the Current HTTP Session Belongs To
        api_response = api_instance.to_session(cookie=cookie)

        pprint(api_response)
    except ory_client.ApiException as e:
        print("Exception when calling V0alpha2Api->to_session: %s\n" % e)
I’m installing a ruby right now. BTW which version of ruby do you use?
f
Ruby 2.6.5, Rails 5.6.5
Copy code
opts = {
  x_session_token: nil,
  cookie: request.env['HTTP_COOKIE']
}
I used the cookie from request
d
I don’t know why configuration does not apply. This happens in Ruby SDK
f
Yes, it is same on my side
Do you have any idea?
d
at the moment no. But you can open an issue in https://github.com/ory/sdk/issues with a description.
f
I see, thanks
d
I think that host overrides somewhere. Because as far as I know it configures the SDK correctly
f
Can I get some expectation when this can be fixed? @User
So, I can decide to wait or switch...
d
As another solution you can call sessions/whoami endpoint without SDK
f
Thanks @User I will check
I created a ticket on the github - https://github.com/ory/sdk/issues/166
d
Okay. Consider calling
sessions/whoami
using http client of your choice
👌 1
👍 1
f
@User In that case, is there any preprocessor which needs to run before calling the API?
d
1. Get cookie from request.cookie 2. Add this cookie to the request to
sessions/whoami
3. Run
That’s all basically
f
Thanks for letting me know. Let me try
l
@User Thx for your help
f
@User It works, thanks
🙌 1