Application tokens
Application tokens are the recommended way to authenticate with the emnify REST API for machine-to-machine (M2M) communications. Unlike user credentials, application tokens don’t require storing passwords on your servers or dealing with multi-factor authentication (MFA).
Key benefits:
- Create multiple tokens for different applications or environments
- Restrict tokens to specific IP address ranges
- Set expiration dates for automatic revocation
- Revoke individual tokens at any time without affecting others
Security best practices:
- Always set an expiration date for production tokens
- Use IP restrictions when your server has a static IP
- Store tokens in environment variables, never in source code
- Rotate tokens periodically and revoke unused tokens
Application tokens are scoped to the Workspace where they were created. Two cross-Workspace operations (Workspace switching and cross-Workspace SIM transfers) temporarily require user credentials, but these APIs are being updated to support application tokens.
Create an application token
To create an application_token, send a POST request to /api/v1/application_token.
You can revoke the application token at any time.
You can also create and view application tokens in the emnify Portal. For step-by-step instructions, see Application tokens.
Authenticate with an application token
Once you create an application token, use /api/v1/authenticate to generate a JWT auth_token that authenticates subsequent API calls.
The server returns only an auth_token.
The response doesn’t include a refresh_token.
Handle token expiration
When an application token expires or is revoked:
- Any
auth_tokengenerated from it remains valid until its own expiration - New authentication attempts with the expired application token fail with a
401 Unauthorizederror - You need to create a new application token and update your application configuration
To avoid service interruptions:
- Set up monitoring for authentication failures
- Create a new application token before the current one expires
- Update your application to use the new token
- Revoke the old token after the transition is complete
Use an SDK
If you prefer to use an SDK instead of direct API calls: