Created
September 27, 2019 18:14
-
-
Save voxelbustersold/a8c828efb84a59b1cd5c4d521ae02941 to your computer and use it in GitHub Desktop.
Game Center External Authentication
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IEnumerator VerifySignature(ExternalAuthenticationCredentials credentials) | |
{ | |
WWWForm form = new WWWForm(); | |
form.AddField("publicKeyUrl", credentials.iOSCredentials.PublicKeyURL); | |
form.AddField("timestamp", System.Convert.ToString(credentials.iOSCredentials.Timestamp)); | |
form.AddField("signature", System.Convert.ToBase64String(credentials.iOSCredentials.Signature)); | |
form.AddField("salt", System.Convert.ToBase64String(credentials.iOSCredentials.Salt)); | |
form.AddField("playerId", NPBinding.GameServices.LocalUser.Identifier); | |
form.AddField("bundleId", NPBinding.Utility.GetBundleIdentifier()); | |
UnityWebRequest www = UnityWebRequest.Post("https://****/authenticate", form); | |
yield return www.SendWebRequest(); | |
if (www.isNetworkError || www.isHttpError) | |
{ | |
Debug.Log(www.error); | |
} | |
else | |
{ | |
Debug.Log("Success response from server! " + www.downloadHandler.text); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Firebase function | |
import * as functions from 'firebase-functions'; | |
import * as verifier from 'gamecenter-identity-verifier'; | |
export const authenticate = functions.https.onRequest((request : any, response : any) => { | |
const identity = { | |
publicKeyUrl: request.body.publicKeyUrl, | |
timestamp: request.body.timestamp, | |
signature: request.body.signature, | |
salt: request.body.salt, | |
playerId: request.body.playerId, | |
bundleId: request.body.bundleId | |
}; | |
console.log("Identity : ", identity); | |
verifier.verify(identity, function (err : any, token : any) { | |
if (!err) { | |
// use token in here. | |
return response.status(200).json({ message : 'successfully verified with details : '+ (JSON.stringify(token)) }); | |
} else { | |
console.error("Error : " , err); | |
return response.status(500).json({ error : err } ); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment