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.
  2. Dismiss Notice

Question Cloud Code Verify Access From Service Account

Discussion in 'Cloud Code' started by defikintaro, Mar 9, 2023.

  1. defikintaro

    defikintaro

    Joined:
    Dec 16, 2022
    Posts:
    9
    Hello,

    I see from the docs, we can run the cloud code scripts from either client or service account. Is there a way to confirm that the caller is a service account in cloud code script side ?
    Thanks !
     
  2. MileyUnity

    MileyUnity

    Unity Technologies

    Joined:
    Jan 3, 2020
    Posts:
    92
    Hi there, It doesn't properly state it here yet but if the playerId is null it means the call was from a service account, if the playerID has any value then it was called by a player.
     
  3. defikintaro

    defikintaro

    Joined:
    Dec 16, 2022
    Posts:
    9
    Thank you ! I've also noticed with a request, userID appended in the context object instead of playerID.
     
  4. MileyUnity

    MileyUnity

    Unity Technologies

    Joined:
    Jan 3, 2020
    Posts:
    92
    Hmm, that sounds odd, could you provide an example of where you found the userId rather than the playerId? Did you perhaps see the `analyticsUserId` instead?
     
    Last edited: Mar 10, 2023
  5. defikintaro

    defikintaro

    Joined:
    Dec 16, 2022
    Posts:
    9
    No, the field is `userId` exactly, when I tru yo call cloud code script with a service account. Also `issuer` field exists.
     
  6. MileyUnity

    MileyUnity

    Unity Technologies

    Joined:
    Jan 3, 2020
    Posts:
    92
    Ah I get it now, the `userId` you're seeing is the service account id, it's not a player ID as the call wasn't made from a player. This means that it's still true that if the `playerId` is null that the call is coming from a service account. I don't 100% know what the `issuer` field would have as a value for your own service accounts but I do know that if a call like this came from the Multiplay product it would have `multiplay` as its issuer to provide you some extra context on who/what is making the call
     
    defikintaro likes this.