- Started a secret rotation.
- Completed a secret rotation.
- Canceled a secret rotation.
Before you start
In order to complete this guide, you’ll need the following:- A Stytch project. If you don’t have one already, in the Dashboard, click on your existing project name in the top left corner of the Dashboard, click Create Project, and then select B2B Authentication.
- The
project_idandsecretfor the Test environment you would like to use. These values can be accessed from the Project ID & API keys section of the Stytch Dashboard. You’ll need to pass these values into theAuthorizationrequest header for most Stytch API calls. - An active M2M Client. If you haven’t created one yet, you can follow the Authenticate an M2M Client guide.
Rotating client secrets
Get the M2M Client
If you completed the Authenticate an M2M Client guide, you should have an active M2M Client. To confirm, call the Get M2M Client endpoint with its The response should look similar to this:The important field to evaluate is
client_id.next_client_secret_last_four. If the value is null, proceed to the next step. If the field is already populated, the client is already in a secret rotation flow. Create a new M2M Client instead.Start the secret rotation
Take the After a successful API call, the response will return the M2M Client with two newly populated fields: At this point, the active M2M Client has two valid secrets associated with it. Both the
client_id of your active M2M Client and call the Start Secret Rotation endpoint.next_client_secret and next_client_secret_last_four.This is the only time you will be able to view the generated
next_client_secret in the API response. Stytch stores a hash of the next_client_secret and cannot recover the value if lost. Be sure to persist the next_client_secret in a secure location. If the next_client_secret is lost, you will need to cancel the secret rotation (Step 4) and start the rotation all over.client_secret and next_client_secret can be used to issue access tokens.This is an opportune time to update your secret store to use the next_client_secret and replace the client_secret for your existing services.Complete the secret rotation
Once updated with A successful API call completes the secret rotation and results in the following updates:
next_client_secret, your services can now retire the client_secret by completing the secret rotation.Call the Rotate Secret endpoint with the client_id.- The M2M Client’s
client_secretfrom Steps 1 and 2 will be invalidated. - The M2M Client’s
client_secretfrom Steps 1 and 2 will be replaced by thenext_client_secret. To confirm, check the M2M Client’sclient_secret_last_fourupdated value. - The M2M Client’s
next_client_secret_last_fourwill be set back tonull.
Cancel the secret rotation (optional)
If for any reason after Step 2 you need to stop or revert the secret rotation process, call the Cancel Secret Rotation endpoint with the A successful API call cancels the secret rotation and results in the following updates:
client_id.- The M2M Client’s
client_secretfrom Steps 1 and 2 will not be updated and will remain valid. - The M2M Client’s
next_client_secretandnext_client_secret_last_fourwill be invalidated and set back tonull.