Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
MastoZap
MastoZap
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 0
    • Issues 0
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge Requests 0
    • Merge Requests 0
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Nathanaël
  • MastoZapMastoZap
  • Wiki
  • oauth2 authentication

Last edited by Nathanaël Sep 27, 2018
Page history

oauth2 authentication

Oauth2 authentication

(cf. Mastodon API doc)

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

https://framapiaf.org/oauth/authorize?scope=read%20write%20follow&response_type=code&redirect_uri=urn:ietf:wg:oauth:2.0:oob&client_id=YOUR_CLIENT_ID

Note that scopes and redirect_uri must match the values provided during app registration.

The access token will be displayed.

With Node libraries

  • https://www.npmjs.com/package/mastodon
  • https://www.npmjs.com/package/mastodon-api

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

  • Making HTTP requests
    // 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')})

Mocks

https://auth-json-server.zapier.ninja

Clone repository
  • dev notes
  • discussions with zapier team
  • Home
  • oauth2 authentication
  • user stories