thefrisson
thefrisson

Reputation: 1

authlib authorize_access_token returns "Invalid client credentials (ID + secret)."

Not sure what's going on here.

I am trying to implement a authlib to access the squarespace API via OAuth. I have implemented github and other 3rd party services with little effort, but specifically with squarespace, errors are persisting. Unfortunately squarespace is crucial to our web application at this point. I have now boiled this down to a very simple flask app as an example. Here is the code:

import os
from authlib.integrations.flask_client import OAuth
from flask import Flask, url_for, redirect


app = Flask(__name__)
app.secret_key = "ghaigeowij"
oauth = OAuth(app)

oauth.register(
    name='squarespace',
    authorize_url='https://login.squarespace.com/api/1/login/oauth/provider/authorize',
    access_token_url='https://login.squarespace.com/api/1/login/oauth/provider/tokens',
    client_id=os.environ.get('SQUARESPACE_CLIENT_ID'),
    client_secret=str(os.environ.get('SQUARESPACE_SECRET_KEY')),
    client_kwargs={
        'scope': 'website.inventory,website.orders',
    },
)

oauth.register(
    name='github',
    client_id=os.environ.get('GITHUB_CLIENT_ID'),
    client_secret=str(os.environ.get('GITHUB_CLIENT_SECRET')),
    access_token_url='https://github.com/login/oauth/access_token',
    authorize_url='https://github.com/login/oauth/authorize',
    api_base_url='https://api.github.com/',
    client_kwargs={'scope': 'user:email'},  # Modify scope as needed
)
@app.route('/login')
def login():
    redirect_uri = "https://platform.orangeisbetter.com/system/oauth/squarespace/callback"
    return oauth.squarespace.authorize_redirect(redirect_uri)

@app.route('/authorize')
def authorize():
    token = oauth.squarespace.authorize_access_token()
    print(token)
    # do something with the token and profile
    return redirect('/')

Here is the current error:

{'type': 'authentication', 'subtype': 'incorrect-client-credentials', 'message': 'Invalid client credentials (ID + secret).', 'details': {'metadata': {}}}

The error shows when I print the token. However, I reached out to the oauth team with squarespace, who said that my credentials are definitely still active. So at this point it comes down to some part of the oauth flow being abstracted incorrectly by authlib/squarespace having a more unique oauth flow. I have looked into the function authorize_access_token. However as others on SO have pointed out authlib is an extensive library and doesn't have a lot of documentation this subject. Also, when reading the oauth docs for squarespace, it looks very typical, and I don't see any discrepancies that would cause this issue. But knowing how this stuff goes, I probably have incorrectly passed a parameter somewhere.

Here are some of the docs I referenced:

Posted the docs in an comment.

Upvotes: 0

Views: 149

Answers (0)

Related Questions