node-gamekit-auth
A simple node.js helper to auth an user using Apple GameKit
Why ?
You now why, like me, you probably lost 2 hours, looking for a simple solution to auth a user to your node.js app using GameKit
Todo
Currently there is no caching, this would probably be something nice to do Also more descriptive error would be cool
Usage
Install
npm install --save gamekit-auth
Simple stupid iOS side example usign Alamofire
import Alamofireimport GameKitclass myCoolVc {func initGK() {let localPlayer = GKLocalPlayer.localPlayer()localPlayer.authenticateHandler = { vc, err inif let vc = vc {self.showViewController(vc, sender: self)} else if localPlayer.authenticated {login(localPlayer) { err indebugPrint(err)// READY TO GO}} else {debugPrint("Noeeeees")}}}func login(localPlayer: GKLocalPlayer, completionHandler: (NSError?) -> Void) {localPlayer.generateIdentityVerificationSignatureWithCompletionHandler { publicKeyUrl, signature, salt, timestamp, err inguard err == nil else { return completionHandler(err) }let parameters = ["playerId": playerId!,"publicKeyURL": publicKeyUrl!.absoluteString,"signature": signature!.base64EncodedStringWithOptions([]),"salt": salt!.base64EncodedStringWithOptions([]),"timestamp": String(timestamp)]Alamofire.request(.POST, YOUR_API_URL, parameters: parameters, encoding: .JSON).validate().responseJSON { response inswitch response.result {case .Success:return completionHandler(nil)case .Failure(let err):return completionHandler(err)}}}}}
Node.js side
var gameKitAuth = ;var bundleIdentifier = 'com.cool-company.cool-app';{;}