Skip to content

Outh 2.0 to Sax bank #149

Closed
Closed

Description

@MislavSag

I am trying to authenticate using Outh 2 on Sax Bank. Here are the docs on sax developer site: https://www.developer.saxo/openapi/learn/oauth-authorization-code-grant

I have successfully authorized using python code:
https://github.com/SaxoBank/openapi-samples-python/tree/master/authentication/oauth
but I can't translate the code in R. I have discovered that redirect url can be set to: http://localhost:4321/redirect

Here is my try:

library(httr2)
#> Warning: package 'httr2' was built under R version 4.1.3
authorization_url = "https://sim.logonvalidation.net/authorize"
token_url = "https://sim.logonvalidation.net/token"
client <- oauth_client(
  id = "xxx",
  secret = "xxx",
  token_url = token_url,,
  # key = "3ebb2f9d91664b92b759ddebafe3437b"
  name = "PRA"
)
url_ <- oauth_flow_auth_code_url(client, 
                                 auth_url = authorization_url, 
                                 redirect_uri = "http://localhost:4321/redirect")
# HOW TO EXECUTE ABOVE URL AND HOW TO DEFINE STATE VARIABLE?

Activity

  1. MislavSag commented on Jun 2, 2022

    @MislavSag
    Author

    After experimenting for some time I have found the solution.

    I had to change some httr2 to be able to use my redirect url.

    For example oauth_flow_auth_code_listen function has line:

    server <- httpuv::startServer(host_ip, port, list(call = listen))
    

    but I need to start the erver on the url http://localhost:4321/redirect

    I am not sure how to add /redirct part to the url.

    Than, in part:

    if (!identical(env$PATH_INFO, "/")) {
    

    I have to add redirect too:

    if (!identical(env$PATH_INFO, "/redirect")) {
    
  2. hadley commented on Jun 2, 2022

    @hadley
    Member

    Does Sax bank require the /redirect in the url that you supply to it?

  3. MislavSag commented on Jul 19, 2022

    @MislavSag
    Author

    It didn't work without /redirect, but I am not sure what are all allowed urls.

  4. hadley commented on Jul 19, 2022

    @hadley
    Member

    httr2 has to listen to specific urls, and it currently only listens to /. If Sax bank requires that /redirect appears in the url, we'll need to make some changes to httr2.

  5. added a commit that references this issue on Aug 29, 2023
    0e18628
  6. added a commit that references this issue on Sep 4, 2023
    1b32d8c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions