I was hoping someone could help me with the OAuth process and getting an application to connect to a project. I am able to complete the OAuth process and get the token in the uri_redirect but I am unable to work out how I let Asana know that the OAuth was successful and the application can be added to the project.
@app.route('/')
def index():
token = session.get('token', False)
# if the user has a token they're logged in
if token:
# example request gets information about logged in user
me = Client(token=token).users.get_user('me')
return render_template_string('''
<script>
window.opener.postMessage("success", "https://app.asana.com");
</script>
<p>Hello {{ name }}.</p>
<p><pre>{{ dump }}</pre></p>
<p><a href="/logout">Logout</a></p>''',
name=me['name'],
dump=json.dumps(me, indent=2)
)
# if we don't have a token show a "Sign in with Asana" button
else:
# get an authorization URL and anti-forgery "state" token
(auth_url, state) = Client().session.authorization_url()
# persist the state token in the user's session
session['state'] = state
# link the button to the authorization URL
return render_template_string('''
<p><a href="{{ auth_url }}"><img src="https://luna1.co/7df202.png"></a></p>''',
auth_url=auth_url
)
but it doesn’t seem to work so I am a bit confused
Most likely it’s the specifics of the implementation in your code there. Have you tried just using the exact code shown in the Asana docs to see if that works? If it does, then you know there’s something about your specific implementation that Asana is not happy with, so to speak.
I seem to have found the issue.
This code works when using Asana in the browser but when I use the Desktop App it doesn’t work. Any chance @Bastien_Siebman or @Phil_Seeman know why that would be the case?
Actually yes. When working on a custom made AppComponent I realized the login wouldn’t go through on the desktop app, and that the rule setup wouldn’t go through on the browser.
So now that you mention it does ring a bell. I mentioned it to the dev team they where surprised by I never got a chance to follow through.