usingSystem;namespaceBest.SignalR.Authentication{publicsealedclassPlayFabAuthenticator:IAuthenticationProvider{/// <summary>/// No pre-auth step required for this type of authentication/// </summary>publicboolIsPreAuthRequired{get{returnfalse;}}#pragma warning disable 0067/// <summary>/// Not used event as IsPreAuthRequired is false/// </summary>publiceventOnAuthenticationSuccededDelegateOnAuthenticationSucceded;/// <summary>/// Not used event as IsPreAuthRequired is false/// </summary>publiceventOnAuthenticationFailedDelegateOnAuthenticationFailed;#pragma warning restore 0067privateHubConnection_connection;privatestring_entityToken;publicPlayFabAuthenticator(HubConnectionconnection,stringentityToken){this._connection=connection;this._entityToken=entityToken;}/// <summary>/// Not used as IsPreAuthRequired is false/// </summary>publicvoidStartAuthentication(){}/// <summary>/// Prepares the request by adding two headers to it/// </summary>publicvoidPrepareRequest(Best.HTTP.HTTPRequestrequest){if(this._connection.NegotiationResult==null){request.SetHeader("X-EntityToken",this._entityToken);return;}// Add Authorization header to http requests, add access_token param to the uri otherwiseif(Best.HTTP.Hosts.Connections.HTTPProtocolFactory.GetProtocolFromUri(request.CurrentUri)==Best.HTTP.Hosts.Connections.SupportedProtocols.HTTP)request.SetHeader("Authorization","Bearer "+this._connection.NegotiationResult.AccessToken);else#if !BESTHTTP_DISABLE_WEBSOCKETif(Best.HTTP.Hosts.Connections.HTTPProtocolFactory.GetProtocolFromUri(request.Uri)!=Best.HTTP.Hosts.Connections.SupportedProtocols.WebSocket)request.Uri=PrepareUriImpl(request.Uri);#else;#endif}publicUriPrepareUri(Uriuri){if(this._connection.NegotiationResult==null)returnuri;if(uri.Query.StartsWith("??")){UriBuilderbuilder=newUriBuilder(uri);builder.Query=builder.Query.Substring(2);returnbuilder.Uri;}#if !BESTHTTP_DISABLE_WEBSOCKETif(Best.HTTP.Hosts.Connections.HTTPProtocolFactory.GetProtocolFromUri(uri)==Best.HTTP.Hosts.Connections.SupportedProtocols.WebSocket)uri=PrepareUriImpl(uri);#endifreturnuri;}privateUriPrepareUriImpl(Uriuri){if(this._connection.NegotiationResult!=null&&!string.IsNullOrEmpty(this._connection.NegotiationResult.AccessToken)){stringquery=string.IsNullOrEmpty(uri.Query)?"":uri.Query+"&";UriBuilderuriBuilder=newUriBuilder(uri.Scheme,uri.Host,uri.Port,uri.AbsolutePath,query+"access_token="+this._connection.NegotiationResult.AccessToken);returnuriBuilder.Uri;}returnuri;}publicvoidCancel(){}}}
The only main change differentiating it from the default access-token authenticator is that this one sets the X-EntityToken header in the PrepareRequest method.
And it can be used while setting up the HubConnection object: