Help with automatically getting a token for Trello using Flask and Python

Dara O hEidhin February 25, 2024

I'm trying to create an internal app to automate Trello and can get a token using the API key if I manually copy and paste from the Trello response.

I wish to automate this using a temporary Flask server. The issue I'm having is that after the authorization callback fires the token is embedded in the redirected URL and I can't seem to find a way to extract it. Any help would be appreciated.

Note the url in the browser after the callback is in the format:<MY TOKEN with 76 characters>

I can't find any way to save/store the token using code and I can't seem to find a way to programmatically access the url in the browser to extract the token characters.

Below is my code. Note that I'm not that familiar with OAuth

``` python

from dataclasses import dataclass

import keyring
from flask import Flask, jsonify, redirect, request, session, url_for
from flask_oauthlib.contrib.client import OAuth
from flask_session import Session
import secrets

from skunkautomation.shared import get_password as get_api_key

app = Flask(__name__)

app.testing = True
app.config["SESSION_TYPE"] = "memcached"
app.config["SECRET_KEY"] = secrets.token_urlsafe(16)

RETURN_URL = "http%3A%2F%2Flocalhost%3A5000%2F"
AUTH_URL = "&".join(

oauth = OAuth(app)
trello = oauth.remote_app(

def home():
    # Check if token is already stored
    token = None  # get_stored_token()
    if token:
        # Use the stored token for API calls
        return "You have a token!"
        # Initiate the authorization flow
        redirect_url = url_for("oauth_callback", _external=True)
        response = trello.authorize(callback_uri=redirect_url)
        return response

def oauth_callback():
    # TODO extract token
    return "blah"  # "Token retrieved successfully!"

if __name__ == "__main__":

I'm getting an email from Attlassian every time I run the code to say "We noticed that you’ve authorized a new application in your Trello account." and if I manually copy the token embedded in the browser URL I can return a list of boards using the code below

from trello import TrelloClient

client = TrelloClient(
    token='<TOKEN copied from callback url>',


# This works

1 answer

0 votes
Alina Kurishko
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 27, 2024

Hi Dara, 

This would be a really great question to share with our developer community. We have a number of Trello Engineers who are active there, and they'd be happy to give some guidance for more advanced topics like these.

Would you please report your question here:

Alina | The Trello Team

Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events