Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 1.4.3 crashes when fetching an access token #31

Open
ollien opened this issue Mar 27, 2024 · 1 comment
Open

Version 1.4.3 crashes when fetching an access token #31

ollien opened this issue Mar 27, 2024 · 1 comment

Comments

@ollien
Copy link

ollien commented Mar 27, 2024

There was a silent change in jsx version 3.0.0 which always adds return_maps to the decode options, unless return_maps is explicitly specified (see: talentdeficit/jsx@fab436e#diff-442484fd845d07345ff2c60c11cb7f83288e6f11299be9b536594b66d3b09d85L75). The README of jsx does seem to confirm this is the default behavior. As a result, most requests for authorization tokens fail with the following, since oauth2c still expects a proplist for access token information.

 =CRASH REPORT==== 27-Mar-2024::18:42:34.779110 ===
   crasher:
     initial call: my_project_conn:init/1
     pid: <0.1107.0>
     registered_name: my_project_conn
     exception error: no function clause matching 
                      proplists:get_value(<<"access_token">>,
                                          #{<<"access_token">> =>
                                                <<"redacted">>,
                                            <<"expires_in">> => 3599,
                                            <<"token_type">> => <<"Bearer">>},
                                          undefined) (proplists.erl, line 215)
       in function  oauth2c:do_retrieve_access_token/2 (/my_project/_build/default/lib/oauth2_client/src/oauth2c.erl, line 229)
       in call from oauth2c:get_access_token/2 (/my_project/_build/default/lib/oauth2_client/src/oauth2c.erl, line 381)
       in call from oauth2c:ensure_client_has_access_token/2 (/my_project/_build/default/lib/oauth2_client/src/oauth2c.erl, line 215)
       in call from oauth2c:request/8 (/my_project/_build/default/lib/oauth2_client/src/oauth2c.erl, line 201)
       in call from my_project_conn:handle_call/3 (/my_project/src/my_project_conn.erl, line 26)
       in call from gen_server:try_handle_call/4 (gen_server.erl, line 661)
       in call from gen_server:handle_msg/6 (gen_server.erl, line 690)
     ancestors: [my_project_sup,<0.1086.0>]
     message_queue_len: 0
     messages: []
     links: [<0.1087.0>]
     dictionary: []
     trap_exit: false
     status: running
     heap_size: 17731
     stack_size: 27
     reductions: 73174
   neighbours:

Version 1.4.2 still works fine, as this uses a 2.x release of jsx (or more accurately, the version of restclient that 1.4.2 depends on uses a 2.x release).

For the sake of providing some reproducing code, here's a lightly edited version of the code I used to reproduce this (though I would be surprised if it weren't reproducible with most flows),

  OAuthClient = oauth2c:from_service_account_file(Path, <<"my-scope">>),
  Res = oauth2c:request(
    post,
    json,
    <<"https://myapi/resource">>,
    [],
    [],
    {}},
    OAuthClient
  ),

I think that this patch would solve the issue, or at the very least put you closer to solving the issue #29

@ollien ollien changed the title Version 1.4.3 crashes when fetching an authorization token Version 1.4.3 crashes when fetching an access token Mar 28, 2024
@ollien
Copy link
Author

ollien commented Apr 1, 2024

Hm, on a whim I tried a fresh project with a more modern version of OTP (the above was using 21, my test project used 26), and this didn't seem to be a problem. I'll have to dig into this more, maybe this is just a non-issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant