Skip to content

Connect a venue

A club connects your app with the OAuth 2 authorization code flow and PKCE (S256). The club's owner approves one club; you receive an access token for that club. Both OAuth URLs are on the main host, https://bookwithmilo.com, not on this developers site.

Authorize URL https://bookwithmilo.com/admin/oauth/authorize
Token URL https://bookwithmilo.com/oauth/token
Scopes read (availability and your bookings), write (create, update and cancel). Without scope you get read only; write alone gets read write.
Authorization code Valid 60 seconds, once
Access token Valid 1 hour
Refresh token Valid 90 days, replaced on every use

Make a PKCE pair

Make a new random verifier for every connect, 43 to 128 characters of A-Z a-z 0-9 - . _ ~. The challenge is the base64url of its SHA-256, without padding. With the example from RFC 7636:

code_verifier dBjftJeZ4CVP-mJ92K27uhbUJU1p1r_wW1gFWFOEjXk
code_challenge E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM
$verifier = rtrim(strtr(base64_encode(random_bytes(32)), '+/', '-_'), '=');
$challenge = rtrim(strtr(base64_encode(hash('sha256', $verifier, true)), '+/', '-_'), '=');
import { createHash, randomBytes } from 'node:crypto';

const verifier = randomBytes(32).toString('base64url');
const challenge = createHash('sha256').update(verifier).digest('base64url');

Keep the verifier on your server with the state you send. plain is refused.

Send the owner to Milo

Redirect the club's owner to the authorize URL:

https://bookwithmilo.com/admin/oauth/authorize?response_type=code
  &client_id=YOUR_CLIENT_ID
  &redirect_uri=https%3A%2F%2Fexample.com%2Fmilo%2Fcallback
  &scope=read%20write
  &state=RANDOM_STATE
  &code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM
  &code_challenge_method=S256

The redirect_uri must equal one Milo registered for the client, character for character; otherwise Milo shows an error and redirects nowhere.

What the owner sees

The owner logs in to the Milo admin (with their second factor if they set one up) and sees your name and logo, the club, what you may do, and: "Players pay the partner. Milo charges no fee and no money passes through Milo." The page is in the owner's language, Dutch or English.

  • Only the club's owner can approve. A manager sees a page saying so, and nothing comes back to you.
  • One approval connects one club. A group with several clubs approves each one.
  • Approve sends the owner to your redirect_uri with code and your state.
  • Deny sends error=access_denied and your state.
  • No PKCE, or a method other than S256, comes back as error=invalid_request on your redirect_uri, or as a 400 from Milo without a redirect; a scope other than read or write as error=invalid_scope.
  • A sandbox client trying a real club, or a live client a sandbox club, comes back as error=access_denied.

Check that state is the one you sent before you use the code.

Exchange the code

Within 60 seconds, post the code with your verifier, form-encoded. The client id and secret go in the body (or as HTTP Basic):

curl https://bookwithmilo.com/oauth/token \
  -d grant_type=authorization_code \
  -d client_id=YOUR_CLIENT_ID \
  -d client_secret=YOUR_CLIENT_SECRET \
  -d redirect_uri=https://example.com/milo/callback \
  -d code=THE_CODE \
  -d code_verifier=dBjftJeZ4CVP-mJ92K27uhbUJU1p1r_wW1gFWFOEjXk
{
  "token_type": "Bearer",
  "expires_in": 3600,
  "access_token": "eyJ0eXAiOiJKV1Qi...",
  "refresh_token": "def50200a1b2...",
  "club_id": "01938a7e-5b1c-7d2e-8f3a-4b5c6d7e8f90"
}

club_id is the club the owner approved. Store it with the tokens: the access token acts on that club only. Another club's availability or bookings answer 403 forbidden, a booking at another club 404 booking_not_found. Treat both tokens as opaque strings.

A code is used once. An expired or reused code, or a wrong verifier, is invalid_grant; a wrong client secret invalid_client. Send the authorize request's redirect_uri: any other is invalid_request. Any refused exchange spends the code; the next try with it is invalid_grant.

Refresh the token

Before the hour is up, or on a 401, trade the refresh token for a new pair:

curl https://bookwithmilo.com/oauth/token \
  -d grant_type=refresh_token \
  -d client_id=YOUR_CLIENT_ID \
  -d client_secret=YOUR_CLIENT_SECRET \
  -d refresh_token=THE_REFRESH_TOKEN

The answer has the same shape, club_id included. Store the new refresh token at once: the old one stops working. Using a refresh token a second time is treated as theft: Milo revokes every token you hold for that club, and the owner has to connect again. If two of your workers can refresh at the same moment, let only one do it.

Do not send scope on a refresh. A refresh that fails still uses up its refresh token: retrying with that token counts as reuse and disconnects the club.

A new approval for the same club replaces the earlier one: the tokens from before stop working.

When a club disconnects

The owner can disconnect your app at any time under Settings, Connected apps. From the next request on, your access token is 401 unauthorized and the refresh token answers invalid_grant. The bookings you made stay, and you still receive their webhooks. To connect again, send the owner through the flow again.

Milo can also suspend a partner; its tokens are then refused the same way.