Issue with returning success back to Asana App

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.

It currently just sits in this state

waiting for a response but I don’t know how to respond. I am doing it in Python and have followed the example server https://github.com/Asana/python-asana/blob/master/examples/example-server.py. If anyone could help that would be greatly appreciated as I have been at this for a week with no luck.

Thanks

1 Like

In the doc there is a link to a GitHub repo with an AppComponent example, the trick is to interact with window.opener. Let me find it.

This is explained here Building app components

1 Like

I thought I was using that in this code

@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

Hi @Mitch_Hare,

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.

Hey Phil,

Yep I am going to try use the below and see what happens, I feel like I am missing something quite small and simple but can’t work it out

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>You have successfully connected Asana to the app</title>
  </head>
  <body>
    Success!
    <script>
      window.opener.postMessage("success", "https://app.asana.com");
      window.close();
    </script>
  </body>
</html>
1 Like

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. :sweat_smile:

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.

1 Like

Yeah, it’s a known thing:

Like @Bastien_Siebman, I don’t know why authentication doesn’t work on the desktop app.

1 Like

Well, that makes me sad!

Now to work out how to attach a resource to do the widget component which is very confusing!

@Mitch_Hare AppComponents are hard, but this is so rewarding when it works!