aaronpk / sign-in-with-apple-example

Sample code for the Sign in with Apple API
https://developer.okta.com/blog/2019/06/04/what-the-heck-is-sign-in-with-apple
Apache License 2.0
154 stars 39 forks source link

How to generate the client_secret using the p8 key ? #9

Open AbhayPai opened 2 years ago

AbhayPai commented 2 years ago

I have all the values which are required, only thing i want as encryption in server level is to generate client_secret value from p8 key value itself. Ex:- from JWKFactory::createFromKeyFile($keyfile) to something like JWKFactory::createFromKey('passing-key-value')

Will this work ?

serhatopcu commented 1 year ago

`require 'jwt' require 'openssl'

team_id = ' ' #app id key_id = ' ' #keys apple client_id = ' ' #bundleid

auth_key = OpenSSL::PKey::EC.new(File.read('AuthKey_XA4T9N4ZK5.p8'))

header = { 'kid': key_id, }

palyload = { 'iss' => team_id, 'iat' => Time.now.to_i, 'exp' => Time.now.to_i + 86400 * 180, # 180 days from now 'aud' => 'client_id write', 'sub' => client_id } token = JWT.encode(palyload, auth_key,'ES256', header)

puts token`

This code will do the job. If you run it with Ruby, you will get the secret key.