I’m working on an macOS client app and was curious what was needed to authorize/login a user to get a token for the auth header?

The lemmy documentation for login doesn’t seem to work (sends 400 response back) and it also doesn’t seem to work with oauth?

I got oauth working for mastodon but those same endpoint calls don’t seem to work for lemmy.

@nmtake@lemm.ee
link
fedilink
3
edit-2
1Y

It seems OAuth2 hasn’t implemented yet. At this time, to get auth value, username and password are required:

# Python
url = 'https://<instance_name>/user/login'
data = {'username_or_email': username_or_email,
        'password': password}
response = requests.post(url, json=data)
json = response.json()
auth = json['jwt']

Since the endpoint recieves JSON then returns JSON, you may need to send following HTTP headers explicitly:

Content-Type: application/json
Accept: application/json
@evilviper@beehaw.org
creator
link
fedilink
21Y

Looking at the lemmy documentation I assumed they wanted form data and sent that along with application/x-www-form-urlencoded for the Content-Type.

As you mention what they actually want is JSON and application/json Content-Type.

Thanks for the info!

PenguinCoder
link
fedilink
11Y

Can you share a minimal reproducible error of your Login functions?

Create a post

All things programming and coding related. Subcommunity of Technology.


This community’s icon was made by Aaron Schneider, under the CC-BY-NC-SA 4.0 license.

  • 1 user online
  • 7 users / day
  • 7 users / week
  • 14 users / month
  • 121 users / 6 months
  • 1 subscriber
  • 296 Posts
  • 2.15K Comments
  • Modlog