Please have look at the JWT token creation code in my comment to this post.
Post
Replies
Boosts
Views
Activity
If I use https://jwt.io to verify the JWT token it always say No valid signature
This is how created my JWT token -
Created a Key from apple developer account (I have an individual account), enable DeviceCheck option during creation of the key.
Downloaded the .p8 file and keep the keyId for later use.
Get the TeamId from the developer account
Using these three information to create the JWT token.
I have added code snippet to create twt token in the reply to this question.