我正在尝试设置 PlayFab + Photon 身份验证。它已经工作了一段时间,但从 Photon Pun 版本 2.46(我更新到新版本)开始,它将显示此错误:
Authenticate without Token is only allowed on Name Server
和 OpAuthenticate failed. Check log output and AuthValues. State: ConnectingToMasterServer
。我不知道有什么方法可以解决这个问题,而且我已经坚持了一段时间了。
我尝试从文档中重写脚本,重新安装 Photon Pun,并重新制作 Photon 应用程序。这些都不起作用。
为了在 Photon 中对用户进行身份验证,您必须提供通过 PlayFab 客户端 API 检索的身份验证令牌。如何检索 Photon 身份验证所需的 Photon 身份验证令牌的示例:
string playFabId = "some ID";
// Use this API to get the token
// takes GetPhotonAuthenticationTokenRequest object which must include your PhotonApplicationId
// Returns GetPhotonAuthenticationTokenResult which includes your token in GetPhotonAuthenticationTokenResult.PhotonCustomAuthenticationToken
PlayFabClientAPI.GetPhotonAuthenticationToken(new GetPhotonAuthenticationTokenRequest
{
// THIS OR YOUR APP ID DEPENDS ON WHAT YOU USE
PhotonApplicationId = PhotonNetwork.PhotonServerSettings.AppSettings.AppIdRealtime,
}, AuthenticatePhoton, OnPlayFabError);
// Use this to authenticate the user in Photon using the token you retrieved above (You can ofcourse separate it, in my example I just connected both.
private void AuthenticatePhoton(GetPhotonAuthenticationTokenResult tokenObj)
{
var customAuth = new AuthenticationValues { AuthType = CustomAuthenticationType.Custom };
customAuth.AddAuthParameter("username", playFabId);
customAuth.AddAuthParameter("token", tokenObj.PhotonCustomAuthenticationToken);
PhotonNetwork.AuthValues = customAuth;
// ConnectUsingSettings() here or whatever is your next steps
}
确保您遵循仪表板设置步骤此处