Colin-b / httpx_auth

Authentication classes to be used with httpx

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow for urn:ietf:wg:oauth:2.0:oob redirect_uri

karolzlot opened this issue · comments

Seems like now it is not possible to remove localhost part from redirect_uri.

I'm getting this error probably because I can't have exactly they same as I type in admin panel of Timely application:

Docs: https://dev.timelyapp.com/#authorization

image

Hi @karolzlot ,

According to the provided documentation, I assume you are using httpx_auth.OAuth2AuthorizationCode ?
The code needs to be retrieved locally, so what would be your use case for a redirect_uri not on localhost?

I assume you receive this rejection because the redirect_uri that you specified as part of your application is not the same as the one used by httpx_auth.OAuth2AuthorizationCode.
If you did not specify any redirection specific settings, the default redirect_uri should be http://localhost:5000/. Can you try adding this URI to your application and try again?

Best Regards

Hi @Colin-b
Thank you for help.

They don't allow me to do this with http://:

image

Additionally it surprises me that I can't give token via variable or input().

I can generate token by hand and then I don't have way to supply it, it seems.

Maybe I could achieve it via json cache, but I'm not sure about format of it.

Also I forgot to give code:

import httpx
from httpx_auth import OAuth2AuthorizationCode
from httpx_auth import OAuth2, JsonTokenFileCache

OAuth2.token_cache = JsonTokenFileCache('./timely1_token_cache.json')

with httpx.Client() as client:
    r = client.get(
        "https://api.timelyapp.com/1.1/accounts",
        auth=OAuth2AuthorizationCode(
            "https://api.timelyapp.com/1.1/oauth/authorize",
            "https://api.timelyapp.com/1.1/oauth/token",
            client_id="XXXXX",
            client_secret="XXXXX",
        ),
    )

Indeed, if they don't allow http redirection, you will have an issue.

Can you try changing this line in your code to use the redirect URI they advise instead ?

Can you confirm that with this change, you will see the code as the title of the browser window (can you check if it is part of the HTML of the page?)?
All I see is some google documentation, I will gladly implement this URI but I need to know the behavior first :)
https://developers.google.com/youtube/v3/live/guides/auth/installed-apps

With:

self.redirect_uri = (
            f"urn:ietf:wg:oauth:2.0:oob"
        )

it opens correct URL (shows token).

This is html of this page:

<html>
<body>
<!--StartFragment-->

  | <!DOCTYPE html>
-- | --
  | <html>
  | <head>
  | <title>OAuth authorization required</title>
  | <meta charset="utf-8">
  | <meta http-equiv="X-UA-Compatible" content="IE=edge">
  | <meta name="viewport" content="width=device-width, initial-scale=1.0">
  | <link rel="stylesheet" media="screen" href="https://d1vbcromo72rmd.cloudfront.net/assets/doorkeeper/application-b789666148ce611da32632a9427e7e0a6df1add18316527c7532d919722dcb6f.css" />
  | <meta name="csrf-param" content="authenticity_token" />
  | <meta name="csrf-token" content="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXaGbFNg==" />
  | </head>
  | <body>
  | <div id="container">
  | <header class="page-header">
  | <h1>Authorization code:</h1>
  | </header>
  | <main role="main">
  | <code id="authorization_code">XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXpw</code>
  | </main>
  | </div>
  | </body>
  | </html>
  |  

<!--EndFragment-->
</body>
</html>

Still error occurs:

Exception has occurred: TimeoutOccurred       (note: full exception trace is shown but execution is paused at: <module>)
User authentication was not received within 60.0 seconds.

Yes error is to be expected for now as it requires a development to be able to fetch the code from the page.
It appears the code is to be extracted from the HTML body. I should be able to do this without too many troubles as there is already some kind of code to handle something similar in the module.

However I don't have the bandwith to do it until the weekend of the 20th. Would that be ok with you?

Hum maybe not that simple after some thought. Can you tell me what was the URL of this page in your browser ?

It's for my side project, it's not urgent for me at all.

URL of this website is:

https://api.timelyapp.com/1.1/oauth/authorize/native?code=XXXXXb-lDXXXXXXXXXXXXXXXXXXXKtC-mXXXXQ

One more thing I wonder is: is the aim of this project the same as Authlib project? Or do you have different direction / design in mind?

I tried both libs and so far I wasn't able to success with any of them, but I'm glad that both exists, I remember I wasn't able to find any good OAuth library some time ago.

I noticed that HTML I posted before was somehow modifed when I copied it from Chrome. When I save source to file I got this:


<!-- saved from url=(0101)https://api.timelyapp.com/1.1/oauth/authorize/native?code=XXXXb-lXXXXXXXXXXXXXXXXXXXXXXXXC-XXXXXXQ -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="color-scheme" content="light dark"></head><body><div class="line-gutter-backdrop"></div><form autocomplete="off"><label class="line-wrap-control">Line wrap<input type="checkbox" aria-label="Line wrap"></label></form><table><tbody><tr><td class="line-number" value="1"></td><td class="line-content"><span class="html-doctype">&lt;!DOCTYPE html&gt;</span></td></tr><tr><td class="line-number" value="2"></td><td class="line-content"><span class="html-tag">&lt;html&gt;</span></td></tr><tr><td class="line-number" value="3"></td><td class="line-content"><span class="html-tag">&lt;head&gt;</span></td></tr><tr><td class="line-number" value="4"></td><td class="line-content"><span class="html-tag">&lt;title&gt;</span>OAuth authorization required<span class="html-tag">&lt;/title&gt;</span></td></tr><tr><td class="line-number" value="5"></td><td class="line-content"><span class="html-tag">&lt;meta <span class="html-attribute-name">charset</span>="<span class="html-attribute-value">utf-8</span>"&gt;</span></td></tr><tr><td class="line-number" value="6"></td><td class="line-content"><span class="html-tag">&lt;meta <span class="html-attribute-name">http-equiv</span>="<span class="html-attribute-value">X-UA-Compatible</span>" <span class="html-attribute-name">content</span>="<span class="html-attribute-value">IE=edge</span>"&gt;</span></td></tr><tr><td class="line-number" value="7"></td><td class="line-content"><span class="html-tag">&lt;meta <span class="html-attribute-name">name</span>="<span class="html-attribute-value">viewport</span>" <span class="html-attribute-name">content</span>="<span class="html-attribute-value">width=device-width, initial-scale=1.0</span>"&gt;</span></td></tr><tr><td class="line-number" value="8"></td><td class="line-content"><span class="html-tag">&lt;link <span class="html-attribute-name">rel</span>="<span class="html-attribute-value">stylesheet</span>" <span class="html-attribute-name">media</span>="<span class="html-attribute-value">screen</span>" <span class="html-attribute-name">href</span>="<a class="html-attribute-value html-resource-link" target="_blank" href="https://d1vbcromo72rmd.cloudfront.net/assets/doorkeeper/application-b789666148ce611da32632a9427e7e0a6df1add18316527c7532d919722dcb6f.css" rel="noreferrer noopener">https://d1vbcromo72rmd.cloudfront.net/assets/doorkeeper/application-b789666148ce611da32632a9427e7e0a6df1add18316527c7532d919722dcb6f.css</a>" /&gt;</span></td></tr><tr><td class="line-number" value="9"></td><td class="line-content"><span class="html-tag">&lt;meta <span class="html-attribute-name">name</span>="<span class="html-attribute-value">csrf-param</span>" <span class="html-attribute-name">content</span>="<span class="html-attribute-value">authenticity_token</span>" /&gt;</span></td></tr><tr><td class="line-number" value="10"></td><td class="line-content"><span class="html-tag">&lt;meta <span class="html-attribute-name">name</span>="<span class="html-attribute-value">csrf-token</span>" <span class="html-attribute-name">content</span>="<span class="html-attribute-value">VPR+wXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX3/F5XXXXX+kXXXXXXXXXXXX/bXXXXXXXXXXS+gg==</span>" /&gt;</span></td></tr><tr><td class="line-number" value="11"></td><td class="line-content"><span class="html-tag">&lt;/head&gt;</span></td></tr><tr><td class="line-number" value="12"></td><td class="line-content"><span class="html-tag">&lt;body&gt;</span></td></tr><tr><td class="line-number" value="13"></td><td class="line-content"><span class="html-tag">&lt;div <span class="html-attribute-name">id</span>="<span class="html-attribute-value">container</span>"&gt;</span></td></tr><tr><td class="line-number" value="14"></td><td class="line-content"><span class="html-tag">&lt;header <span class="html-attribute-name">class</span>="<span class="html-attribute-value">page-header</span>"&gt;</span></td></tr><tr><td class="line-number" value="15"></td><td class="line-content"><span class="html-tag">&lt;h1&gt;</span>Authorization code:<span class="html-tag">&lt;/h1&gt;</span></td></tr><tr><td class="line-number" value="16"></td><td class="line-content"><span class="html-tag">&lt;/header&gt;</span></td></tr><tr><td class="line-number" value="17"></td><td class="line-content"><span class="html-tag">&lt;main <span class="html-attribute-name">role</span>="<span class="html-attribute-value">main</span>"&gt;</span></td></tr><tr><td class="line-number" value="18"></td><td class="line-content"><span class="html-tag">&lt;code <span class="html-attribute-name">id</span>="<span class="html-attribute-value">authorization_code</span>"&gt;</span>XXXXb-lXXXXXXXXXXXXXXXXXXXXXXXXC-XXXXXXQ<span class="html-tag">&lt;/code&gt;</span></td></tr><tr><td class="line-number" value="19"></td><td class="line-content"><span class="html-tag">&lt;/main&gt;</span></td></tr><tr><td class="line-number" value="20"></td><td class="line-content"><span class="html-tag">&lt;/div&gt;</span></td></tr><tr><td class="line-number" value="21"></td><td class="line-content"><span class="html-tag">&lt;/body&gt;</span></td></tr><tr><td class="line-number" value="22"></td><td class="line-content"><span class="html-tag">&lt;/html&gt;</span></td></tr><tr><td class="line-number" value="23"></td><td class="line-content"><span class="html-end-of-file"></span></td></tr></tbody></table></body></html>