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
- C#
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(),
});
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
- C#
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;
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
- C#
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