Welcome to the Kinde community.

A
A
A
M
T

Generating client secret for apple social sign in using typescript

How could I generate the client secret for Apple social sign in using TypeScript?

K
M
3 comments

To generate the client secret for Apple social sign in using TypeScript, you can follow these steps: 1. *Install the necessary libraries*: You will need the `jsonwebtoken` library to create and sign JWT tokens. Install it using npm or yarn: ``` npm install jsonwebtoken ``` 2. *Create a script to generate the client secret*: Create a file named `generateClientSecret.ts` and add the following code: ``` import * as fs from 'fs'; import * as jwt from 'jsonwebtoken'; const keyFile = 'path/to/your/key.p8'; // Path to your .p8 file const teamId = 'YOUR_TEAM_ID'; // Your Apple Developer Team ID const clientId = 'YOUR_CLIENT_ID'; // Your Service ID const keyId = 'YOUR_KEY_ID'; // Key ID from the .p8 file const privateKey = fs.readFileSync(keyFile); const headers = { kid: keyId, alg: 'ES256' }; const claims = { iss: teamId, iat: Math.floor(Date.now() / 1000), exp: Math.floor(Date.now() / 1000) + 86400 * 180, // 6 months expiration aud: '', sub: clientId }; const token = jwt.sign(claims, privateKey, { algorithm: 'ES256', header: headers }); console.log(token); ``` 3. *Run the script*: Execute the script using ts-node or compile it to JavaScript and run it with Node.js: ``` npx ts-node generateClientSecret.ts ``` This will output the generated `client_secret` token. 4. *Add the credentials to Kinde*: • Go to `Settings > Authentication` in Kinde. • On the Apple tile, select `Configure`. • Paste the `Client ID` (Service ID) and `Client secret` (generated token) into the relevant fields. • Select which apps will use Apple sign in. • Select `Save`. Users will now see Apple as an option to sign up and sign in to your product.

How can I test the Apple social login on localhost?

To test the Apple social login on localhost, follow these steps: 1. *Set up your Apple Developer account*: • Ensure you have an Apple Developer account and have subscribed to the Apple Developer Program. 2. *Create and configure your app in the Apple Developer account*: • Go to Identifiers and create a new App ID. • Register a new Services ID and make a note of the identifier (this will be your Client ID). • Configure the domains and return URLs: • In the Domains and Subdomains field, enter your Kinde URL, e.g., `` (excluding the https:// protocol). • In the Return URLs field, enter your Kinde callback URL, e.g., ``. 3. *Set up keys*: • Create a new key in the Apple Developer account, enable "Sign In with Apple," and download the key file (.p8). 4. *Generate the client secret*: • Use a script to generate the client secret. Here is an example using TypeScript: ``` import * as fs from 'fs'; import * as jwt from 'jsonwebtoken'; const keyFile = 'path/to/your/key.p8'; // Path to your .p8 file const teamId = 'YOUR_TEAM_ID'; // Your Apple Developer Team ID const clientId = 'YOUR_CLIENT_ID'; // Your Service ID const keyId = 'YOUR_KEY_ID'; // Key ID from the .p8 file const privateKey = fs.readFileSync(keyFile); const headers = { kid: keyId, alg: 'ES256' }; const claims = { iss: teamId, iat: Math.floor(Date.now() / 1000), exp: Math.floor(Date.now() / 1000) + 86400 * 180, // 6 months expiration aud: '', sub: clientId }; const token = jwt.sign(claims, privateKey, { algorithm: 'ES256', header: headers }); console.log(token); ``` • Run the script to generate the client secret. 5. *Add the credentials to Kinde*: • Go to `Settings > Authentication` in Kinde. • On the Apple tile, select `Configure`. • Paste the `Client ID` (Service ID) and `Client secret` (generated token) into the relevant fields. • Select which apps will use Apple sign in. • Select `Save`. 6. *Set up your local environment*: • Ensure your local development environment is configured to use the correct callback URLs. For example, set the `Allowed callback URLs` to `` in your Kinde application settings. 7. *Test the login*: • Run your application locally. • Navigate to the login page and select the Apple sign-in option. • Follow the prompts to sign in with your Apple credentials. By following these steps, you should be able to test the Apple social login on your localhost environment.

Add a reply
Sign up and join the conversation on Slack
Join