Photon C++ Client API  5.0.7.3
Public Member Functions | List of all members
AuthenticationValues Class Reference
Inheritance diagram for AuthenticationValues:
Inheritance graph
[legend]
Collaboration diagram for AuthenticationValues:
Collaboration graph
[legend]

Public Member Functions

 AuthenticationValues (void)
 
nByte getType (void) const
 
AuthenticationValuessetType (nByte type)
 
const Common::JStringgetParameters (void) const
 
AuthenticationValuessetParameters (const Common::JString &parameters)
 
AuthenticationValuessetParametersWithUsernameAndToken (const Common::JString &username, const Common::JString &token)
 
const Common::ObjectgetData (void) const
 
AuthenticationValuessetData (const Common::JVector< nByte > &data)
 
AuthenticationValuessetData (const Common::JString &data)
 
AuthenticationValuessetData (const Common::Dictionary< Common::JString, Common::Object > &data)
 
const Common::JStringgetSecret (void) const
 
const Common::JStringgetUserID (void) const
 
AuthenticationValuessetUserID (const Common::JString &userID)
 
virtual Common::JStringtoString (Common::JString &retStr, bool withTypes=false) const
 
virtual JStringtoString (JString &retStr, bool withTypes=false) const=0
 
JString toString (bool withTypes=false) const
 
- Public Member Functions inherited from ToString
virtual ~ToString (void)
 
virtual JString typeToString (void) const
 
JString toString (bool withTypes=false) const
 

Detailed Description

Container for user authentication in Photon.

Remarks
On Photon, user authentication is optional but can be useful in many cases. If you want to use Client::opFindFriends(), a unique ID per user is very practical.

There are basically three options for user authentication: None at all, the client sets some UserId or you can use some account web-service to authenticate a user (and set the UserId by that auth service).

Custom Authentication lets you verify end-users by some kind of login or token. It sends those values to Photon which will verify them before granting access or disconnecting the client.

If you don't set a user ID through setUserID() for the AuthenticationValues instance that you pass to Client::connect() and you neither set one in your auth service (or don't use an auth service), then Photon generates a unique user ID (which fulfills the requirements of a GUID) for you, which (as well as a userId that is set by your auth service) can be retrieved through Client::getUserID(), once the Client instance has notified Listener::connectReturn() about having successfully finished the connection procedure. Once you have set a user ID, the Client instance caches it until you either override it or until the end of the lifetime of the Client instance.

Note
If both, the client and the auth service, set a userID, then the one that is set by the auth service, takes priority.
Remarks
There are three ways that a userID can be set in Photon (order in their priority from highest to lowest: lower priority values get ignored if higher ones are present) a) it can be set by the auth service b) it can be set through the client side AuthenticationValues c) it can be set by the server Option c) has the lowest priority and only happens if neither the client nor the auth service sets one. Option a) has the highest priority and overrides any value that is set by option b). When a client sends its authentication request, it sends the user id that you have set on the client side, if such is present. The servers response to a successful authentication contains the user id for that client. In case that the auth service has provided an id, the servers response will contain this id. In case that neither the auth service nor the client has provided a user id, the servers response will contain a server generated GUID for the the user id. In case that the client, but not the auth service has provided one, the user id in the servers response will match the one that the client has sent in its request. The client then applies the user id that the server has provided locally.

To be able to rejoin a room and to be recognized there as the previous user it is critical to continue to use the same user ID.

For this reason you should store the user ID in permanent storage and set it to that same stored value whenever you want to connect as that user, even if you let Photon initially generate that ID. Otherwise Photon would generate a new user ID for you whenever you construct a new Client instance (i.e. when the user restarts your app).

Constructor & Destructor Documentation

◆ AuthenticationValues()

Constructor.

Member Function Documentation

◆ getType()

nByte getType ( void  ) const
Returns
the type of the "Custom Authentication"service that will be used.
See also
setType()

◆ setType()

AuthenticationValues & setType ( nByte  type)

Sets the type of the "Custom Authentication" service that will be used. The initial value before the first call to this function is CustomAuthenticationType::NONE.

Note
Any custom authentication type aside from CustomAuthenticationType::NONE requires you to set up an authentication service of matching type for your appID at https://www.photonengine.com/dashboard
Parameters
typeneeds to match one of the values in CustomAuthenticationType
Returns
a reference to the instance on which it was called to allow for chaining multiple setter calls
See also
getType(), CustomAuthenticationType

◆ getParameters()

const JString & getParameters ( void  ) const
Returns
the HTTP GET parameters that will be forwarded to the authentication service.
See also
setParameters(), setParametersWithUsernameAndToken(), getData(), setData()

◆ setParameters()

AuthenticationValues & setParameters ( const Common::JString parameters)

Sets the HTTP GET parameters that will be forwarded to the authentication service to the provided parameters.

The provided parameter string must contain any (HTTP GET) parameters that are expected by the used authentication service.

Remarks
Standard HTTP GET parameters are used here and passed on to the authentication service that's defined for the provided authentication type in the Photon Cloud Dashboard.
Parameters
parametersneeds to be a valid HTTP GET string (i.e. param1=value1&param2=value2&param3=value3)
Returns
a reference to the instance on which it was called to allow for chaining multiple setter calls
See also
getParameters(), setParametersWithUsernameAndToken(), getData(), setData()

◆ setParametersWithUsernameAndToken()

AuthenticationValues & setParametersWithUsernameAndToken ( const Common::JString username,
const Common::JString token 
)

Sets the HTTP GET parameters that will be forwarded to the authentication service to the provided username and token.

Calling this function is equivalent to setParameters(L"username=" + username + "&token=" + token).

Parameters
usernamethe username of the user that should be authenticated
tokenthe authentication token needed by the authentication service to verify the user
Returns
a reference to the instance on which it was called to allow for chaining multiple setter calls
See also
getParameters(), setParameters(), getData(), setData()

◆ getData()

const Object & getData ( void  ) const
Returns
the HTTP POST data that will be forwarded to the authentication service.
See also
getParameters(), setParameters(), setParametersWithUsernameAndToken(), setData()

◆ setData() [1/3]

AuthenticationValues & setData ( const Common::JVector< nByte > &  data)

Sets the HTTP POST data, that will be forwarded to the authentication service, to the provided data.

The provided data needs to match what is expected by the used authentication service.

Remarks
The provided data is passed on to the authentication service that's defined for the provided authentication type in the Photon Cloud Dashboard.
Parameters
datathe data to be used in the body of the POST request
Returns
a reference to the instance on which it was called to allow for chaining multiple setter calls
See also
getParameters(), setParameters(), setParametersWithUsernameAndToken(), getData()

◆ setData() [2/3]

AuthenticationValues & setData ( const Common::JString data)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This overload accepts JString data.

Parameters
datathe data to be used in the body of the POST request

◆ setData() [3/3]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This overload accepts Dictionary<JString, Object> data, which will be converted to Json by the server before it gets passed-on to the authentication service.

Parameters
datathe data to be used in the body of the POST request

◆ getSecret()

const JString & getSecret ( void  ) const

After initial authentication, Photon provides a secret for this client / user, which is subsequently used as (cached) validation internally.

Remarks
This is publicly read-accessible only for debugging purposes. For normal operations it is entirely unnecessary for the app code to ever access this value.
Returns
the cached secret

◆ getUserID()

const JString & getUserID ( void  ) const
Returns
the unique user ID
See also
setUserID()

◆ setUserID()

AuthenticationValues & setUserID ( const Common::JString userID)

Sets the unique user ID.

Parameters
userIDa string that needs to be unique per user among all users of your app
Returns
a reference to the instance on which it was called to allow for chaining multiple setter calls
See also
getUserID()

◆ toString() [1/3]

JString & toString ( Common::JString retStr,
bool  withTypes = false 
) const
virtual
Remarks
The cost of this function depends a lot on implementation details of the implementing subclasses, but for container classes this function can become quite expensive, if the instance contains huge amounts of data, as its cost for many container class implementations increases disproportionately high to the size of the payload.
Parameters
retStrreference to a string, to store the return-value in; the information, which is generated by this function, will be attached at the end of any eventually existing previous content of the string
withTypesset to true, to include type information in the generated string
Returns
a JString representation of the instance and its contents for debugging purposes.

Implements ToString.

◆ toString() [2/3]

toString
Remarks
The cost of this function depends a lot on implementation details of the implementing subclasses, but for container classes this function can become quite expensive, if the instance contains huge amounts of data, as its cost for many container class implementations increases disproportionately high to the size of the payload.
Parameters
retStrreference to a string, to store the return-value in; the information, which is generated by this function, will be attached at the end of any eventually existing previous content of the string
withTypesset to true, to include type information in the generated string
Returns
a JString representation of the instance and its contents for debugging purposes.

◆ toString() [3/3]

JString toString

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
withTypesset to true, to include type information in the generated string
Returns
a JString representation of the instance and its contents for debugging purposes.
See also
JString