Authentication
When a site owner installs your app, they will grant you permission to collect their site data during the installation flow, which is based on the settings you provide in the Wix Developers Center. You will then receive an authorization code which you will use to request an access token and a refresh token. Then you’ll pass the access token as an authorization header in the API call.
Note:
Access and refresh tokens are user-specific. Access tokens are valid for 5 minutes. Refresh tokens are valid as long as the app is installed on the user's site.
Note: In certain installation flows, Wix will load your app and redirect URLs in an iframe. Make sure your content can be loaded on an iframe. For example, make sure you don't send the header 'X-FRAME-OPTIONS'
The OAuth Flow
We use OAuth 2.0 to authorize you to access our APIs and receive webhooks.
Note:
You’ll need to set up OAuth, Permissions, and Webhooks settings in the Wix Developers Center.
Step 1: User Installs Your App
If the user chooses to install your app from within the Wix App Market, we redirect users to the App URL you defined in the Wix Developers Center. We include a token
query parameter when we direct users to your App URL (we use it to keep track of the user as they go through the OAuth flow).
Note:
This redirect to the App URL is a back-end process only. The user shouldn't have to log in or sign up here - send them straight to the authorization request step described next.
Important:
If the user installs your app from your own platform, skip this step and go straight to step 2.
Step 5: App Receives Access and Refresh Tokens
Wix will respond to your request in step 4 with a JSON response containing an access token and a refresh token (These tokens are not relevant for webhooks):
Copy Code{"refresh_token": <REFRESH_TOKEN>,"access_token": <FRESH_ACCESS_TOKEN>}
Note:
Request a new access token every time you call an API. Access tokens expire after 5 minutes. Use your refresh token to request a new access token.
Step 5a: App Completes the OAuth Flow
Note: This step is only required for apps that display their consent in a new window, not a new tab. This is primarily for apps with a dashboard component that opens inside of Wix as an iframe, or another internal component.
Now that you have access and refresh tokens, you must close the consent window by redirecting the user to the following URL with the user's access token after the equals sign (=
):
Copy Codehttps://www.wix.com/installer/close-window?access_token=<ACCESS_TOKEN>
Step 6: App Requests Protected Data
Follow our API Reference section to request the user's protected data, with a fresh access token as the authorization header.
Important:
For all future API calls, you will need to request a new access token, using the refresh token you received in step 5.
Step 7: App Finishes Installation
At this point your app is designated “Setup Incomplete”. This state is useful if your app requires users to create an account or set other configuration parameters in order for the app to become active.
Once your app requires on further setup steps, create the following request to mark the installation as finished:
Copy Codecurl -X POST \https://www.wixapis.com/apps/v1/bi-event \-H 'Authorization: <AUTH>' \-d '{"eventName": "APP_FINISHED_CONFIGURATION"}’\
Note: Until the endpoint is called, the app is marked as "Setup Incomplete" in the Wix database.
Was this helpful?
In This Article
Step 1: User Installs Your App Step 2: App Sends Users to Authorize the App Step 2a: User Authorizes the App Step 3: Wix Redirects the User to App Server With an Authorization Code Step 4: App Submits the Authorization Code Step 5: App Receives Access and Refresh Tokens Step 5a: App Completes the OAuth Flow Step 6: App Requests Protected Data Step 7: App Finishes Installation