<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Trouble getting the user object post login]]></title><description><![CDATA[<p dir="auto">Hello,</p>
<p dir="auto">I'm using <code>FusionAuth</code> to handle the login and authentication functionality in my application. I've been able to successfully setup <code>FusionAuth</code> and a simple <code>Flask</code> based python application that implements the required callbacks. In the first version, the callbacks didn't perform any operation other than rendering a simple HTML template with success message. With this I was able to login and logout successfully.</p>
<p dir="auto">However, when I try to enhance the code to get access token and user on a successful login, I keep getting a <code>401</code> error message. I'm following the quick setup tutorial <a href="https://fusionauth.io/docs/v1/tech/5-minute-setup-guide" rel="nofollow ugc">here</a> with the exception of using corresponding functions in python. My code is as below:</p>
<pre><code>from app import app
from flask import request, render_template

from fusionauth.fusionauth_client import FusionAuthClient


client_id = "&lt;my-id&gt;"
client_secret = "&lt;my-secret&gt;"

client = FusionAuthClient(client_id, "http://&lt;my-ip&gt;:9011")

@app.route("/")
def index():
    # Render a simple page with a login button
    return render_template("public/index.html")


@app.route("/oauth-callback")
def oauth_callback():
    resp = client.exchange_o_auth_code_for_access_token(request.args.get("code"), client_id, client_secret, "http://&lt;my-ip&gt;:5000/oauth-callback")

    print(resp.status)
    # Render a simple page with a login succeeded message and a logout button
    return render_template("public/logged_in.html")


@app.route("/logout")
def logout():
    # Render a simple page with a logout successful message
    return render_template("public/logged_out.html")
</code></pre>
<p dir="auto">The call to <code>exchange_o_auth_code_for_access_token</code> always returns <code>401</code> no matter what value I provide for the URL parameter. I'm not sure what I'm doing wrong and would appreciate any help.</p>
<p dir="auto">Thanks in advance!<br />
-N</p>
]]></description><link>https://fusionauth.io/community/forum/topic/311/trouble-getting-the-user-object-post-login</link><generator>RSS for Node</generator><lastBuildDate>Thu, 15 Oct 2026 07:34:03 GMT</lastBuildDate><atom:link href="https://fusionauth.io/community/forum/topic/311.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 21 Aug 2020 04:11:47 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Trouble getting the user object post login on Fri, 23 Oct 2020 23:19:43 GMT]]></title><description><![CDATA[<p dir="auto"><a class="mention plugin-mentions-user plugin-mentions-a" href="https://fusionauth.io/community/forum/uid/20">@dan</a> Thank you for your support. Fixing the signature just saved me another couple of hours (also coming from <a href="https://fusionauth.io/blog/2020/07/14/django-and-oauth/" rel="nofollow ugc">https://fusionauth.io/blog/2020/07/14/django-and-oauth/</a>) ^^</p>
]]></description><link>https://fusionauth.io/community/forum/post/1514</link><guid isPermaLink="true">https://fusionauth.io/community/forum/post/1514</guid><dc:creator><![CDATA[amine.hosni]]></dc:creator><pubDate>Fri, 23 Oct 2020 23:19:43 GMT</pubDate></item><item><title><![CDATA[Reply to Trouble getting the user object post login on Tue, 13 Oct 2020 03:36:41 GMT]]></title><description><![CDATA[<p dir="auto">Thanks <a class="mention plugin-mentions-user plugin-mentions-a" href="https://fusionauth.io/community/forum/uid/341">@ralph</a> . I just updated the site ( <a href="https://github.com/FusionAuth/fusionauth-site/pull/247" rel="nofollow ugc">https://github.com/FusionAuth/fusionauth-site/pull/247</a> ) and the fixes should go out in a day or so.</p>
]]></description><link>https://fusionauth.io/community/forum/post/1431</link><guid isPermaLink="true">https://fusionauth.io/community/forum/post/1431</guid><dc:creator><![CDATA[dan]]></dc:creator><pubDate>Tue, 13 Oct 2020 03:36:41 GMT</pubDate></item><item><title><![CDATA[Reply to Trouble getting the user object post login on Sat, 10 Oct 2020 20:27:35 GMT]]></title><description><![CDATA[<p dir="auto">Thanks all for this - I too fell into the trap. It looks like the docs I was following have the wrong signature for the <code>exchange_o_auth_code_for_access_token</code> function: <a href="https://fusionauth.io/blog/2020/07/14/django-and-oauth" rel="nofollow ugc">https://fusionauth.io/blog/2020/07/14/django-and-oauth</a></p>
<p dir="auto">It should of course read:</p>
<pre><code>r = client.exchange_o_auth_code_for_access_token(
      code,
      settings.FUSION_AUTH_APP_ID,
      redirect_url,
      settings.FUSION_AUTH_CLIENT_SECRET,
    )
</code></pre>
<p dir="auto">(incidentally, the docs use CLIENT_ID in this function call, but never actually try to set it - so it should be APP_ID as here)</p>
]]></description><link>https://fusionauth.io/community/forum/post/1425</link><guid isPermaLink="true">https://fusionauth.io/community/forum/post/1425</guid><dc:creator><![CDATA[ralph]]></dc:creator><pubDate>Sat, 10 Oct 2020 20:27:35 GMT</pubDate></item><item><title><![CDATA[Reply to Trouble getting the user object post login on Sat, 29 Aug 2020 00:27:41 GMT]]></title><description><![CDATA[<p dir="auto">Thanks Dan! It all works now.</p>
]]></description><link>https://fusionauth.io/community/forum/post/1023</link><guid isPermaLink="true">https://fusionauth.io/community/forum/post/1023</guid><dc:creator><![CDATA[nishant]]></dc:creator><pubDate>Sat, 29 Aug 2020 00:27:41 GMT</pubDate></item><item><title><![CDATA[Reply to Trouble getting the user object post login on Fri, 28 Aug 2020 18:41:41 GMT]]></title><description><![CDATA[<p dir="auto">OK, we just released 1.18.8 and that is the version you want to use:</p>
<p dir="auto">In <code>requirements.txt</code>:</p>
<pre><code>fusionauth-client==1.18.8
</code></pre>
<p dir="auto">And then this is the call you want to make (with <code>client_id</code> before <code>redirect_uri</code>) :</p>
<pre><code> resp = client.exchange_o_auth_code_for_access_token(request.args.get("code"), client_id, "http://localhost:5000/oauth-callback", client_secret)
</code></pre>
]]></description><link>https://fusionauth.io/community/forum/post/1021</link><guid isPermaLink="true">https://fusionauth.io/community/forum/post/1021</guid><dc:creator><![CDATA[dan]]></dc:creator><pubDate>Fri, 28 Aug 2020 18:41:41 GMT</pubDate></item><item><title><![CDATA[Reply to Trouble getting the user object post login on Fri, 28 Aug 2020 17:42:54 GMT]]></title><description><![CDATA[<p dir="auto">OK, I did take a look.</p>
<p dir="auto">The issue is that there was a recent change to the client library which switched the order of arguments.</p>
<p dir="auto">This is the set of arguments that worked for me:</p>
<pre><code> resp = client.exchange_o_auth_code_for_access_token(request.args.get("code"), "http://localhost:5000/oauth-callback", client_id, client_secret)
</code></pre>
<p dir="auto">But I asked the engineering team when they'd be releasing the newest version of the libs, which will change it to</p>
<pre><code> resp = client.exchange_o_auth_code_for_access_token(request.args.get("code"), client_id, "http://localhost:5000/oauth-callback", client_secret)
</code></pre>
<p dir="auto"><code>client_id</code> and <code>redirect_uri</code> swapped places.</p>
<p dir="auto">Once I did that, when I logged in, I saw:</p>
<pre><code>success
{'access_token': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImRkMDYxMjY4YWMifQ.eyJhdWQiOiIzODU1ZGMyMC0yNzQ3LTQwYzEtYTUyMC1hODc3NzYxYmY5YjYiLCJleHAiOjE1OTg2Mzk2MTMsImlhdCI6MTU5ODYzNjAxMywiaXNzIjoiYWNtZS5jb20iLCJzdWIiOiIwMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAwMDQiLCJqdGkiOiIwYWYzNDlkMy04ZTQ5LTQ0ZDEtYmE5NS04NmM2N2I4NzAzODkiLCJhdXRoZW50aWNhdGlvblR5cGUiOiJQQVNTV09SRCIsImVtYWlsIjoiZGluZXNoQGZ1c2lvbmF1dGguaW8iLCJlbWFpbF92ZXJpZmllZCI6dHJ1ZSwiYXBwbGljYXRpb25JZCI6IjM4NTVkYzIwLTI3NDctNDBjMS1hNTIwLWE4Nzc3NjFiZjliNiIsInJvbGVzIjpbXX0.RXdPUtk_vtRbNva__O8OBLFdUv8aZubewkXmK9Pnr2g', 'expires_in': 3599, 'token_type': 'Bearer', 'userId': '00000000-0000-0000-0000-000000000004'}
</code></pre>
<p dir="auto">If you want to get further user info, you can use the <code>userId</code> to look stuff up via the APIs. You could also make a request to the <code>Userinfo</code> endpoint, but if you do so, you need to request the <code>openid</code> scope initially.</p>
<p dir="auto">I also noticed that the API call was failing. Make sure you create your client with the API key, which is different than the client id:</p>
<pre><code>client = FusionAuthClient('APIKEY', "http://localhost:9011")
</code></pre>
<p dir="auto">Will let you know what I hear back, but until then you should look at <a href="https://github.com/FusionAuth/fusionauth-python-client/blob/1.18.0/src/main/python/fusionauth/fusionauth_client.py" rel="nofollow ugc">https://github.com/FusionAuth/fusionauth-python-client/blob/1.18.0/src/main/python/fusionauth/fusionauth_client.py</a> to see the proper order of args, because that is the published version.</p>
]]></description><link>https://fusionauth.io/community/forum/post/1014</link><guid isPermaLink="true">https://fusionauth.io/community/forum/post/1014</guid><dc:creator><![CDATA[dan]]></dc:creator><pubDate>Fri, 28 Aug 2020 17:42:54 GMT</pubDate></item><item><title><![CDATA[Reply to Trouble getting the user object post login on Fri, 28 Aug 2020 12:57:44 GMT]]></title><description><![CDATA[<p dir="auto"><a class="mention plugin-mentions-user plugin-mentions-a" href="https://fusionauth.io/community/forum/uid/20">@dan</a> Hi Dan, just circling back. Did you have a chance to look into this? Thanks!</p>
]]></description><link>https://fusionauth.io/community/forum/post/1011</link><guid isPermaLink="true">https://fusionauth.io/community/forum/post/1011</guid><dc:creator><![CDATA[nishant]]></dc:creator><pubDate>Fri, 28 Aug 2020 12:57:44 GMT</pubDate></item><item><title><![CDATA[Reply to Trouble getting the user object post login on Thu, 27 Aug 2020 01:08:11 GMT]]></title><description><![CDATA[<p dir="auto"><a class="mention plugin-mentions-user plugin-mentions-a" href="https://fusionauth.io/community/forum/uid/20">@dan</a> No worries! Thanks for all your help! You can download the application zip file from <a href="https://temp-fusionauth.s3.amazonaws.com/sample_app.zip" rel="nofollow ugc">here</a>. As you'll notice, its a pretty simple app. Also I've replaced all the <code>ip addresses</code> and <code>ids</code> for security reasons so while the app won't run as is, you would still be able to get an idea of the functionality. Thanks again for your continued support! Hoping to resolve this soon!</p>
]]></description><link>https://fusionauth.io/community/forum/post/994</link><guid isPermaLink="true">https://fusionauth.io/community/forum/post/994</guid><dc:creator><![CDATA[nishant]]></dc:creator><pubDate>Thu, 27 Aug 2020 01:08:11 GMT</pubDate></item><item><title><![CDATA[Reply to Trouble getting the user object post login on Wed, 26 Aug 2020 19:12:47 GMT]]></title><description><![CDATA[<p dir="auto">Hiya,</p>
<p dir="auto">Thanks for your patience. I'm not quite sure what is going on.</p>
<p dir="auto">Can you provide your code in a github repo or other place I can take a look at the whole project, please?</p>
]]></description><link>https://fusionauth.io/community/forum/post/982</link><guid isPermaLink="true">https://fusionauth.io/community/forum/post/982</guid><dc:creator><![CDATA[dan]]></dc:creator><pubDate>Wed, 26 Aug 2020 19:12:47 GMT</pubDate></item><item><title><![CDATA[Reply to Trouble getting the user object post login on Tue, 25 Aug 2020 22:46:10 GMT]]></title><description><![CDATA[<p dir="auto"><a class="mention plugin-mentions-user plugin-mentions-a" href="https://fusionauth.io/community/forum/uid/20">@dan</a> Thanks for the response. I did double check my application code and there was a client id mismatch in one of the URIs in my application code. I fixed that. However I'm still getting <code>401</code>. Below is the flask server output:</p>
<pre><code>&lt;Response [401]&gt;
error
&lt;Response [401]&gt;
74.15.29.84 - - [25/Aug/2020 22:43:04] "GET /oauth-callback?code=9E2MtFiIkFTS1uRBDjNXIOwLDuefGNLMqreSo1gZL2A&amp;locale=en_US&amp;userState=Authenticated HTTP/1.1" 200 -```
</code></pre>
<p dir="auto">As you can see the state has changed to <code>Authenticated</code> now.</p>
]]></description><link>https://fusionauth.io/community/forum/post/963</link><guid isPermaLink="true">https://fusionauth.io/community/forum/post/963</guid><dc:creator><![CDATA[nishant]]></dc:creator><pubDate>Tue, 25 Aug 2020 22:46:10 GMT</pubDate></item><item><title><![CDATA[Reply to Trouble getting the user object post login on Tue, 25 Aug 2020 15:08:03 GMT]]></title><description><![CDATA[<p dir="auto"><a class="mention plugin-mentions-user plugin-mentions-a" href="https://fusionauth.io/community/forum/uid/225">@nishant</a> said in <a href="/community/forum/post/934">Trouble getting the user object post login</a>:</p>
<blockquote>
<p dir="auto"><code>&amp;userState=AuthenticatedNotRegistered</code></p>
</blockquote>
<p dir="auto">There's the issue. Are you sure that you:</p>
<ul>
<li>registered the user to the application</li>
<li>are passing the correct client id for the application</li>
</ul>
<p dir="auto">Because it seems like FusionAuth recognizes the user, but not that they are registered to the application.</p>
<p dir="auto">Can you double check both of those? (I know you checked that the user was registered before, but can you double check?)</p>
]]></description><link>https://fusionauth.io/community/forum/post/953</link><guid isPermaLink="true">https://fusionauth.io/community/forum/post/953</guid><dc:creator><![CDATA[dan]]></dc:creator><pubDate>Tue, 25 Aug 2020 15:08:03 GMT</pubDate></item><item><title><![CDATA[Reply to Trouble getting the user object post login on Mon, 24 Aug 2020 15:50:13 GMT]]></title><description><![CDATA[<p dir="auto"><a class="mention plugin-mentions-user plugin-mentions-a" href="https://fusionauth.io/community/forum/uid/20">@dan</a> That is correct. Below is the output on flask server:</p>
<pre><code>&lt;Response [401]&gt;
error
&lt;Response [401]&gt;
74.15.29.84 - - [24/Aug/2020 15:46:33] "GET /oauth-callback?code=q0AEmFiDNOjWiGlBa64Ea7MI2BlwotSh7AAcqqjWSt4&amp;locale=en_US&amp;userState=AuthenticatedNotRegistered HTTP/1.1" 200 -
</code></pre>
]]></description><link>https://fusionauth.io/community/forum/post/934</link><guid isPermaLink="true">https://fusionauth.io/community/forum/post/934</guid><dc:creator><![CDATA[nishant]]></dc:creator><pubDate>Mon, 24 Aug 2020 15:50:13 GMT</pubDate></item><item><title><![CDATA[Reply to Trouble getting the user object post login on Mon, 24 Aug 2020 13:33:02 GMT]]></title><description><![CDATA[<p dir="auto">OK, so the user is able to login when you are logging them into the application directly, is that correct?</p>
<p dir="auto">But you get a 401 whenever you are requesting a token.</p>
<p dir="auto">Interesting.</p>
<p dir="auto">Can you try to make a different call with the client object, just to make sure you are initializing it correctly?</p>
<pre><code>client_response = client.retrieve_user_by_email('you@example.com')
if client_response.was_successful():
    print(client_response.success_response)
else:
    print(client_response.error_response)
</code></pre>
<p dir="auto">Can you try adding this code just after you call <code>client.exchange_o_auth_code_for_access_token</code>?</p>
<pre><code>if resp.was_successful():
    print("success")
    print(resp.success_response)
else:
    print("error")
    print(resp.error_response)
</code></pre>
<p dir="auto">And let me know what you see when running your flask server.</p>
]]></description><link>https://fusionauth.io/community/forum/post/921</link><guid isPermaLink="true">https://fusionauth.io/community/forum/post/921</guid><dc:creator><![CDATA[dan]]></dc:creator><pubDate>Mon, 24 Aug 2020 13:33:02 GMT</pubDate></item><item><title><![CDATA[Reply to Trouble getting the user object post login on Sat, 22 Aug 2020 22:33:15 GMT]]></title><description><![CDATA[<p dir="auto"><a class="mention plugin-mentions-user plugin-mentions-a" href="https://fusionauth.io/community/forum/uid/20">@dan</a> Thanks for the response. I changed the call to <code>exchange_o_auth_code_for_access_token</code> swapping <code>client_secret</code> and <code>redirect_uri</code> args. I made sure that the user is registered with the application to which they are trying to authorize and that the <code>redirect_uri</code> is setup correctly in application config. I'm attaching screen shots from the FusionAuth app. I'm still getting a <code>401</code> response.</p>
<p dir="auto">l would also would like to mention as an aside that the user is able to login successfully to this app. I get <code>401</code> for the auth code request post successful login.</p>
<p dir="auto">Redirect URI setup:<br />
<img src="/community/forum/assets/uploads/files/1598135520153-redirecuri.jpg" alt="RedirecURI.jpg" class=" img-fluid img-markdown" /></p>
<p dir="auto">User Registration:<br />
<img src="/community/forum/assets/uploads/files/1598135550551-userreg.png" alt="UserReg.png" class=" img-fluid img-markdown" /></p>
]]></description><link>https://fusionauth.io/community/forum/post/913</link><guid isPermaLink="true">https://fusionauth.io/community/forum/post/913</guid><dc:creator><![CDATA[nishant]]></dc:creator><pubDate>Sat, 22 Aug 2020 22:33:15 GMT</pubDate></item><item><title><![CDATA[Reply to Trouble getting the user object post login on Fri, 21 Aug 2020 18:12:21 GMT]]></title><description><![CDATA[<p dir="auto">Hiya,</p>
<p dir="auto">A few troubleshooting tips:</p>
<ul>
<li>Is your user registered with the application to which they are trying to authorize?</li>
<li>From <a href="https://github.com/FusionAuth/fusionauth-python-client/blob/master/src/main/python/fusionauth/fusionauth_client.py" rel="nofollow ugc">https://github.com/FusionAuth/fusionauth-python-client/blob/master/src/main/python/fusionauth/fusionauth_client.py</a> it looks like the signature is: <code>def exchange_o_auth_code_for_access_token(self, code, client_id, redirect_uri, client_secret=None):</code> so it seems you have the <code>redirect_uri</code> and the <code>client_secret</code> transposed.</li>
<li>Do you have the <code>redirect_uri</code> set up correctly in the FusionAuth application config?</li>
</ul>
]]></description><link>https://fusionauth.io/community/forum/post/900</link><guid isPermaLink="true">https://fusionauth.io/community/forum/post/900</guid><dc:creator><![CDATA[dan]]></dc:creator><pubDate>Fri, 21 Aug 2020 18:12:21 GMT</pubDate></item></channel></rss>