Authenticating with the Edge Client
Certain actions on the Edge Client will require your users to be authenticated. We recommend authenticating your players before attempting to perform game actions using the Edge Client.
You'll need to first create a Honeycomb user before authenticating using the information below.
Authenticating with the Edge Client
Authentication using Edge Client is a 2 step process. First, send an auth request query like this:
- JavaScript
- GraphQL
- Unity/C#
- Godot
const {
authRequest: { message: authRequest }
} = await client.authRequest({
userPublicKey.toString()
});
query AuthRequestQuery($wallet: String!) {
authRequest(wallet: $wallet)
}
You will need to include the user's wallet address in the query:
{
"wallet": "pubkey" // User's wallet address in string format
}
var authmsg = await Client.AuthRequest(new AuthRequestParams
{
Wallet = Web3.Wallet.Account.PublicKey.ToString(),
});
client.auth_request(wallet)
var auth_response = await client.query_response_received
var message: PackedByteArray = String(auth_response.authRequest.message).to_ascii_buffer()
In return you'll get a response like this:
{
"data": {
"message": "Please sign this message to authenticate to Honeycomb unified interface: 3CzXyQb2NVuXaKuQJ26FTqWcdXxirGvbJ2RNPpXCA9Mj"
}
}
Next, you will need sign this message:
- Front-end
- Server-side
- Unity/C#
- Godot
import { useWallet } from "@solana/wallet-adapter-react";
import base58 from "bs58";
// Get the user's wallet
const wallet = useWallet();
// Convert the auth request into a UInt8Array
const encodedMessage = new TextEncoder().encode(authRequest);
// Sign the message
const signedUIntArray = await wallet.signMessage(encodedMessage);
// Convert the signed message into a base58 encoded string
const signature = base58.encode(signedUIntArray);
// Send the signed message to the server
const { authConfirm } = await client.authConfirm({ wallet: userPublicKey.toString(), signature });
import * as web3 from "@solana/web3.js";
import nacl from "tweetnacl";
import base58 from "bs58";
// Define a signMessage function
const signAuthRequest = (authRequest: string, keypair: web3.Keypair) => {
const messageBytes = new TextEncoder().encode(authRequest);
const signatureBytes = nacl.sign.detached(messageBytes, keypair.secretKey);
return base58.encode(signatureBytes);
};
// Sign the message
const signature = signAuthRequest(authRequest, userKeypair);
// Send the signed message to the server
const { authConfirm } = await client.authConfirm({ wallet: userPublicKey.toString(), signature });
var msgToSign = authmsg.AuthRequest.Message.Trim().Replace("\u200B", "");
var messageBytes = Encoding.UTF8.GetBytes(msgToSign);
//Debug.Log(msgToSign);
var sign = await Web3.Wallet.SignMessage(messageBytes);
// Debug.Log("Signature Valid: " + Web3.Wallet.Account.PublicKey.Verify(messageBytes, sign));
//Send the signed message to the server
var authToken = await Client.AuthConfirm(new AuthConfirmParams
{
Wallet = Web3.Wallet.Account.PublicKey.ToString(),
Signature = Encoders.Base58.EncodeData(sign)
});
// accessToken
var accessToken = authToken.AuthConfirm.AccessToken;
var signedMsg: PackedByteArray = user_keypair.sign_message(message)
var signature = SolanaUtils.bs58_encode(sig)
client.auth_confirm(wallet, signature)
var confirm_response = await client.query_response_received
var auth_token = confirm_response.authConfirm.accessToken
After you've sent the signed message to the server, you'll get an access token and a user object containing the details of the user. You can use the access token to authenticate the user in subsequent requests. Here's an example:
- Frontend/ServerSide
- Unity/C#
- Godot
const { createNewProfileTransaction: txResponse } =
await client.createNewProfileTransaction(
{
project: projectAddress,
info: {
name: `Test profile`,
bio: `This is a test profile`,
pfp: "https://www.example.com/pfp.png",
},
payer: userPublicKey.toString(),
},
{
fetchOptions: {
headers: {
authorization: `Bearer ${accessToken}`,
},
},
}
);
var newProfileTransaction = await Client.CreateNewProfileTransaction(new CreateNewProfileTransactionParams
{
Project = projectAddress,
Info = new ProfileInfoInput
{
Name = "Test profile",
Bio = "This is a test profile",
Pfp = "https://www.example.com/pfp.png"
},
Payer = userPublicKey // The public key of the user who is creating the profile
},
authToken: accessToken;
var txResponse = newProfileTransaction.CreateNewProfileTransaction; // This is the transaction response, you'll need to sign and send this transaction
var profile_info_input: ProfileInfoInput = load("res://resources/new_profile_info_input.tres")
profile_info_input.name = "Test profile"
profile_info_input.bio = "This is a test"
profile_info_input.pfp = "https://www.example.com/pfp.png"
client.create_new_profile_transaction(
project_address,
payer_address,
"", // Identity type in string, the value depends on the project's needs
profile_info_input,
)
var response = await client.query_response_received
var transaction = response.createNewProfileTransaction.tx