Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question Uploading data for foreign authentication

Discussion in 'Cloud Save' started by DasMaffin, Oct 6, 2022.

  1. DasMaffin

    DasMaffin

    Joined:
    Apr 3, 2018
    Posts:
    4
    I have a multiplayer application, and I do not want the player to be able to access his data on his own, instead I currently use authentication and cloud saves to save and load player data. However the server of course isn't authenticated like the user is, so I want to give the server the users Auth ID and then upload data from the server to the cloud.
    Basically I want the server to work like an admin, having the rights over multiple users.
    My last approach was to queue an authentication that will authenticate the server AS the user, upload the data, and then immediately lo out again, but I feel like there has to be an easier way (Because I can think of multiple errors happening with my current approach on the top of my head)
     
  2. eduardoojeda

    eduardoojeda

    Unity Technologies

    Joined:
    Dec 23, 2020
    Posts:
    4
    Hello! There is indeed a better way to accomplish what you're after. You can create a Service Account and use it on your server to access Cloud Save as an admin, so you can have rights over any one of your player's data. You can find the docs for it here: Admin API Authentication

    Something may not be completely evident from the docs I linked above, though: For your case you will want to access the Cloud Save Game APIs (instead of the Admin APIs), as you want to modify data on behalf of your game players. As you can see in the Game API docs, you will need send a stateless token (JWT) in the Authentication header to access those. You can obtain a JWT for your Service Account using the token exchange mechanism. Keep in mind these stateless tokens expire for security reasons, so you will need to periodically refresh them. Let us know if you run into any issues and we'll make sure to help you out!