1.0.3 • Published 6 years ago
login-apple-token-validator v1.0.3
Login with Apple Token Validator
During a Sign up with Apple from a mobile client the backend needs to receive a token and then to verify that the token is valid. The process is not as simple therefore I am creating this package.
Installation
npm install login-apple-token-validatorUse of framework
var validator = require('login-apple-token-validator')
const appIds = ['<Your application ID (Bundle Identificator)>']
const token = '<Token received from Sign up with Apple>'
validator.verifyToken(token, appIds).then(function(decodedJWTPayload){
console.log(decodedJWTPayload) // will return parsed JWT payload from Apple's token
}, function(error) {
console.log(error) // will show an error
})Backend implementation guidelines
- Create an endpoint to receive the
tokenprovided by Apple - Use the framework to validate if the token is valid or not. If the token is valid continue to step 3, If the token is invalid return an error response.
- The following fields from
decodedJWTPayloadneeds to be stored in your DB:email- email of the user. As it may be a private email it is recommended to use the property below to identify a user.sub- JWT subject, the unique user ID provided to you by Apple. Use this property to identify the user as theemailproperty may change.
- If the user is already available in your system proceed with your standard Login procedure, else proceed with your register procedure.
License - MIT
Contribution
Feel free to contribute and extend the current project. The standard git procedures need to be followed:
- Create a PR
- Explain the changes that your are applying
- Rebase on the latest master if needed