Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Add script to generate Apple SSO client Secret #10890

Open
wants to merge 20 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
d588754
Add script to generate Apple SSO client Secret
muradkhateeb78 Aug 6, 2024
491cae0
Update code to generate Apple SSO Client Secret
muradkhateeb78 Aug 6, 2024
bcc1f7f
Refactor pieces of code
muradkhateeb78 Aug 6, 2024
7c280a5
Use CLI to pass the Apple SSO secret generation args
muradkhateeb78 Aug 6, 2024
582c206
Merge branch 'dev' into Add-Apple-SSO-Secret-Generation-Script
muradkhateeb78 Aug 6, 2024
455a786
chore: Update create-apple-sso-secret script to remove unnecessary ar…
muradkhateeb78 Aug 6, 2024
90c3cf7
Merge branch 'Add-Apple-SSO-Secret-Generation-Script' of https://gith…
muradkhateeb78 Aug 6, 2024
f4d0812
Fix imports
muradkhateeb78 Aug 6, 2024
99588e8
Format document and fix imports
muradkhateeb78 Aug 6, 2024
ed1bb51
Merge branch 'dev' into Add-Apple-SSO-Secret-Generation-Script
muradkhateeb78 Aug 6, 2024
b280eb0
Fixed import of JWT
hanzlamateen Aug 6, 2024
d857948
Reverted encoding in file read
hanzlamateen Aug 6, 2024
9d4d2e2
Remove unncessary encoding while reading the file
muradkhateeb78 Aug 6, 2024
a8e8186
Merge branch 'Add-Apple-SSO-Secret-Generation-Script' of https://gith…
muradkhateeb78 Aug 6, 2024
a820b18
Remove licence details for the time being
muradkhateeb78 Aug 6, 2024
9f40d05
Merge branch 'dev' into Add-Apple-SSO-Secret-Generation-Script
barankyle Aug 7, 2024
f549b84
Rename the script for generating the client secret for Apple
muradkhateeb78 Aug 8, 2024
8beeb0f
Fix build checks
muradkhateeb78 Aug 8, 2024
bd923ac
Add script to generate Apple client secret
muradkhateeb78 Aug 8, 2024
2bafe81
Merge branch 'dev' into Add-Apple-SSO-Secret-Generation-Script
muradkhateeb78 Aug 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"lint": "prettier --check \"packages/**/*.{ts,tsx}\"",
"local": "npm run dev-docker && cross-env VITE_LOCAL_BUILD=true LOCAL=true concurrently -n agones,server,worldserver,mediaserver,client npm:dev-agones-silent \"cd packages/server && npm run start\" \"cd packages/instanceserver && npm run start\" \"cd packages/instanceserver && npm run start-channel\" \"cd packages/client && npm run local\"",
"make-user-admin": "cross-env ts-node --swc scripts/make-user-admin.ts",
"generate-apple-client-secret": "cross-env ts-node --swc scripts/generate-apple-client-secret.ts",
"migrate": "cd packages/server-core && npm run migrate",
"migrate:rollback": "cd packages/server-core && npm run migrate:rollback",
"migrate:unlock": "cd packages/server-core && npm run migrate:unlock",
Expand Down
69 changes: 69 additions & 0 deletions scripts/generate-apple-client-secret.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
CPAL-1.0 License

The contents of this file are subject to the Common Public Attribution License
Version 1.0. (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
https://github.com/EtherealEngine/etherealengine/blob/dev/LICENSE.
The License is based on the Mozilla Public License Version 1.1, but Sections 14
and 15 have been added to cover use of software over a computer network and
provide for limited attribution for the Original Developer. In addition,
Exhibit A has been modified to be consistent with Exhibit B.

Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
specific language governing rights and limitations under the License.

The Original Code is Ethereal Engine.

The Original Developer is the Initial Developer. The Initial Developer of the
Original Code is the Ethereal Engine team.

All portions of the code written by the Ethereal Engine team are Copyright © 2021-2023
Ethereal Engine. All Rights Reserved.
*/

import logger from '@etherealengine/server-core/src/ServerLogger'
import cli from 'cli'
import fs from 'fs'
import Jwt from 'jsonwebtoken'

cli.enable('status')

cli.main(async () => {
try {
const creds = cli.parse({
secretKeyPath: ['', 'Path to Apple SSO secret key.p8', 'string'],
keyId: ['', 'Key ID of the Secret Key generated in Apple Developer Account', 'string'],
teamId: ['', 'Team ID of the Apple Developer Account', 'string'],
clientId: ['', 'The client ID of the service ID created in the Apple Developer Account', 'string']
})
if (!creds.secretKeyPath || !creds.keyId || !creds.teamId || !creds.clientId) {
cli.fatal('Please provide all the required arguments')
}
const privateKey = fs.readFileSync(creds.secretKeyPath)

const claims = {
iss: creds.teamId,
aud: 'https://appleid.apple.com',
sub: creds.clientId
}

const clientSecret = Jwt.sign(claims, privateKey, {
algorithm: 'ES256',
header: {
alg: 'ES256',
kid: creds.keyId,
typ: 'JWT'
},
expiresIn: '180d' // The token will expire in 180 days. The token can be set to expire in a shorter time but not more than 6 months.
})

logger.info(clientSecret)
process.exit(0)
} catch (err) {
console.log('Error while generating client secret for Apple')
console.log(err)
cli.fatal(err)
}
})
Loading