Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seemingly grant_type=password no longer supported for ver 4.4.0 #387

Closed
mike-enker opened this issue Nov 8, 2024 · 8 comments
Closed

Seemingly grant_type=password no longer supported for ver 4.4.0 #387

mike-enker opened this issue Nov 8, 2024 · 8 comments

Comments

@mike-enker
Copy link

Needs to change to grant_type=client_credentials.

There might be more issues with the release compatibility...

@mike-enker
Copy link
Author

Looks like v4.4.0 no longer supports the basic authentication and posting order flow. One needs to create an application in the Web UI (Preferences/Development). The resulting Application will have the access token that one can use for
mastodon = Mastodon(api_base_url='https://mastodon.social/')
mastodon.access_token = 'hgfhgfhgfhgfhgfhgfh'

Then toot away!

@andypiper
Copy link
Contributor

This is correct, we are moving away from allowing apps to provide a username and password on API calls in v4.4 and beyond. This is not as secure as the OAuth tokens.

@ThisIsMissEm
Copy link

ThisIsMissEm commented Nov 13, 2024

You can also discover if this grant type is supported via the /.well-known/oauth-authorization-server endpoint on the server, see: https://docs.joinmastodon.org/methods/oauth/#authorization-server-metadata

It's been removed because it's been regarded as highly insecure for a long time and is actually completely removed in the upcoming OAuth 2.1 internet draft.

Whilst you could use client_credentials if you're doing anything on behalf of a user, you'll want the authorization_code setup, or, as mentioned above a static out-of-band provisioned personal access token for an OAuth Application

@halcy
Copy link
Owner

halcy commented Dec 1, 2024

I believe we already fully support the OAuth flow as it is (with infinitely persistable token / no refresh). Not sure there is any need to try to support the client credential to client-only access token flow, but probably not - actions can already be performed on behalf of a client by just passing client_id and client_secret directly, and the entire "managing client IDs" part is kind of vestigial (since fully automated by necessity) for fedi servers anyways, what matters is getting the user access token.

TODOs here I think are adjusting docs to note deprecation of the u/pw flow, adjusting sample code where needed, and apologizing to downstream users for the breaking change.

@ThisIsMissEm
Copy link

There are some use-cases in the future that may exist for actual client_credentials grant type, but generally it's not the one you want for most mastodon APIs. You almost always want either a Personal Access Token (provisioned from the Development menu and tied to your specific account) or using authorization code grant flow for multiple user applications.

We may also in the future support Device Code Authorization Grant Flow for devices with limited input (e.g., IOT / TVs / Retrocomputers), but that's still being figured out since we can't implement straight away.

@CortexReaver
Copy link

CortexReaver commented Feb 4, 2025

pls change the main page description on https://mastodonpy.readthedocs.io/en/stable/index.html# then, because right now it is very confusing and I has waste a lot of time figuring what was wrong with my script.
Only the method described by mike-enker is working for me, "Mastodon.auth_request_url" has not done anything useful for me as well - it gave me a code, which I was desperatly tried to use with "Mastodon.log_in" with no result.

@andypiper
Copy link
Contributor

The relevant file to edit / patch is this one - it should be updated to remove the username/password example and use an OAuth example instead.

@halcy
Copy link
Owner

halcy commented Feb 13, 2025

Updated readme and docs, added an error message that is more descriptive than a nondescript API error when someone tries to log into a 4.4+ instance using password grant

@halcy halcy closed this as completed Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants