Oauth2 authentication
curl -X POST \
-F "client_name=Zapier" \
-F "redirect_uris=urn:ietf:wg:oauth:2.0:oob" \
-F "scopes=read write follow" \
https://framapiaf.org/api/v1/apps
Note that redirect_uris
can be an actual redirection URL. You can also add the website
field.
You will get something like:
{"id":"42","name":"Zapier","redirect_uri":"urn:ietf:wg:oauth:2.0:oob","client_id":"YOUR_CLIENT_ID","client_secret":"YOUR_CLIENT_SECRET"}
Get the access token
Then, use the client_id
and client_secret
values to acquire an access token:
with curl and grant password
curl -X POST \
-F "client_id=YOUR_CLIENT_ID" \
-F "client_secret=YOUR_CLIENT_SECRET" \
-F "grant_type=password" \
-F "username=YOUR_EMAIL" \
-F 'password=YOUR_PASSWORD' \
https://framapiaf.org/oauth/token
You will get something like:
{"access_token":"YOUR_ACCESS_TOKEN","token_type":"Bearer","scope":"read","created_at":1536500708}
With the Mastodon web UI
Note that scopes
and redirect_uri
must match the values provided during app registration.
The access token will be displayed.
With Node libraries
With Zapier
- https://framagit.org/roipoussiere/MastoZap/wikis/home#mail-sent-to-zapier-team-in-french
- https://zapier.github.io/zapier-platform-cli/#oauth2
- https://github.com/zapier/zapier-platform-example-app-oauth2/blob/master/authentication.js
- https://github.com/zapier/zapier-platform-example-app-github/blob/master/authentication.js
Let's check this
curl --header "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-sS https://framapiaf.org/api/v1/accounts/verify_credentials
You will get basic information about your account:
{"id":"98885","username":"roipoussiere","acct":"roipoussiere","display_name":"Nathanaël (compte de secours)","locked":false,"bot":false,[...]
\o/
mastodon-api node module
// For OAuth we store `access_token` and `refresh_token` automatically
// in `bundle.authData` for future use. If you need to save/use something
// that the user shouldn't need to type/choose, add a "computed" field, like:
// {key: 'something': type: 'string', required: false, computed: true}
// And remember to return it in oauth2Config.getAccessToken/refreshAccessToken
let m = require('mastodon-api');
const SERVER_NAME = 'https://framapiaf.org';
// To be called only once for each server
let app = m.createOAuthApp(SERVER_NAME + '/api/v1/apps', 'Zapier', 'read');
// To be called only once for each user
let auth = app.then(data => {m.getAuthorizationUrl(data.client_id, data.client_secret, 'authorization_code', 'read')})