Skip to content

Latest commit

 

History

History
128 lines (91 loc) · 3.08 KB

File metadata and controls

128 lines (91 loc) · 3.08 KB

OAuth2 Authentication Example

This guide walks you through setting up OAuth2 authentication with Exact Online.

Prerequisites

  1. An Exact Online account
  2. An Exact Online App registered at Exact Online App Center
  3. Your App credentials:
    • Client ID
    • Client Secret
    • Redirect URI (must match your app settings)

Step 1: Register Your App

  1. Go to Exact Online App Center
  2. Create a new app
  3. Note your Client ID and Client Secret
  4. Set your Redirect URI (e.g., http://localhost:8080/callback)

Step 2: Configure Your Application

Using Environment Variables

export EXACT_ONLINE_CLIENT_ID=your-client-id
export EXACT_ONLINE_CLIENT_SECRET=your-client-secret
export EXACT_ONLINE_DIVISION_ID=your-division-id
export EXACT_ONLINE_REDIRECT_URI=http://localhost:8080/callback

Using .env File

# .env
EXACT_ONLINE_CLIENT_ID=your-client-id
EXACT_ONLINE_CLIENT_SECRET=your-client-secret
EXACT_ONLINE_DIVISION_ID=your-division-id
EXACT_ONLINE_REDIRECT_URI=http://localhost:8080/callback

Step 3: Get Your Division ID

Method 1: From URL

  1. Log into Exact Online
  2. Check your URL: https://start.exactonline.nl/[DIVISION_ID]/
  3. Copy the Division ID

Method 2: From API (After Authentication)

curl -H "Authorization: Bearer YOUR_TOKEN" \
  "https://start.exactonline.nl/api/v1/current/Me?\$select=CurrentDivision"

Step 4: Start the Application

docker-compose up -d

Or run directly:

mvn spring-boot:run

Step 5: Authorize Your Application

Option A: Direct Authorization URL

  1. Construct the authorization URL:
https://start.exactonline.nl/api/oauth2/auth?
  client_id=YOUR_CLIENT_ID&
  redirect_uri=YOUR_REDIRECT_URI&
  response_type=code&
  force_login=0
  1. Open in browser and authorize
  2. You'll be redirected to your callback URL with a code parameter

Option B: Use the Callback Endpoint

  1. Visit: http://localhost:8080/callback?code=YOUR_AUTHORIZATION_CODE
  2. The application will exchange the code for tokens automatically
  3. Tokens are stored in the database

Step 6: Verify Authentication

Check the logs to confirm:

INFO  - Token exchange successful
INFO  - Token stored in database

Or check the database:

SELECT * FROM exact_online_token ORDER BY created_at DESC LIMIT 1;

Token Refresh

The application automatically refreshes tokens when they expire. No additional configuration needed!

Troubleshooting

"Invalid client credentials"

  • Verify your Client ID and Client Secret
  • Ensure they match your Exact Online App settings

"Redirect URI mismatch"

  • Check that your redirect URI exactly matches the one in your app settings
  • Ensure URL encoding is correct

"Division not found"

  • Verify your Division ID is correct
  • Ensure you have access to the division

Next Steps

Once authenticated, you can:

  • Fetch accounts: GET /api/v1/internal/exact-online/accounts
  • Fetch subscriptions: GET /api/v1/internal/exact-online/subscriptions
  • Set up webhooks: POST /api/v1/webhook/subscribe