Hi,
I’m implementing a custom authentication flow using Unity for the client and Go for the backend code, and I’ve run into two problems.
1. AuthenticateTokenGenerate
does not return a refresh token
initializer.RegisterHttp("/login-custom", func(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
// 1. Custom login logic …
customID := "my_custom_id"
// 2. Create / link the user
userId, userName, _, err := nk.AuthenticateCustom(ctx, customID, "", true)
// 3. Generate a session token for this user
token, _, err := nk.AuthenticateTokenGenerate(ctx, userId, userName, 0, nil)
// refreshToken ← missing
…
})
AuthenticateTokenGenerate
returns only the access token (token
) and norefresh_token
.- On the client I restore the session with
Nakama.Session.Restore(token)
, but later calls to
Client.SessionRefreshAsync()
fail with “missing refresh token” (Same problem occurs whenAutoRefreshSession
is enabled).
2. Sessions are accepted on any server, without validation
During development, I first run the Nakama server locally using Docker Desktop and connect my Unity client to 127.0.0.1
to obtain a session token.
Later, I change the client’s server address to point to my production server and continue using the same token that was originally generated by the local server. Surprisingly, all requests are still accepted by the production server, even though the token was not issued by it.
However, requests that involve user-scoped storage eventually fail with the following error:
Error running multi update.
error: ERROR: insert on table "storage"
violates foreign key constraint "storage_user_id_fkey" (SQLSTATE 23503)
This suggests the backend is not validating that the session was issued by the current server (or matching environment).
Questions
- Should
AuthenticateTokenGenerate
return a refresh token? If not, what is the recommended way to refresh sessions created server‑side? - How can we ensure that sessions are valid only on the server that issued them (e.g., by hostname, key, or environment)?
Any guidance would be greatly appreciated, as we’d like to ship with a robust custom login.
{Details}
- Versions: Nakama {3.27.1}, {Docker}, {client library nakama-unity v3.16.0}
- Server Framework Runtime language {Go}
Thanks for your help!