Super App Integration
Overall Flow
thông tin
This is an example is almost follow the authentication method when integrate between Mini App and Telegram
thông tin
Below is an example on how to generate a initData for the authentication flow
Code Sample
- Generate initData via Go
- Generate initData via NodeJS
func main() {
secret := "<tenant_api_key>"
tenantPlayerID := "<tenant_player_id>"
tenantPlayerToken := "<tenant_player_token>"
playerName := "<player_name>"
avatar := "https://example.com/avatar.jpg"
authDate := time.Now().Unix()
params := map[string]string{
"tenant_player_id": tenantPlayerID,
"tenant_player_token": tenantPlayerToken,
"name": playerName,
"avatar": avatar,
"auth_date": fmt.Sprint(authDate),
}
var hashParams []string
for k, v := range params {
if len(v) > 0 {
hashParams = append(hashParams, fmt.Sprintf("%s=%s", k, v))
}
}
sort.Strings(hashParams)
hashKey := sha256.New()
hashKey.Write([]byte(secret))
hmac := hmac.New(sha256.New, hashKey.Sum(nil))
hmac.Write([]byte(strings.Join(hashParams, "\n")))
hash := hex.EncodeToString(hmac.Sum(nil))
params["hash"] = hash
v, _ := json.Marshal(params)
fmt.Println(string(v))
}
const crypto = require('crypto');
const secret = '<tenant_api_key>';
const tenantPlayerID = '<tenant_player_id>';
const tenantPlayerToken = '<tenant_player_token>';
const playerName = '<player_name>';
const avatar = 'https://example.com/avatar.jpg';
const authDate = Math.floor(Date.now() / 1000);
const params = {
tenant_player_id: tenantPlayerID,
tenant_player_token: tenantPlayerToken,
name: playerName,
avatar: avatar,
auth_date: authDate,
};
const hashParams = Object.entries(params)
.map(([key, value]) => `${key}=${value}`)
.sort()
.join('\n');
const hashKey = crypto.createHash('sha256').update(secret).digest();
const hmac = crypto.createHmac('sha256', hashKey);
hmac.update(hashParams);
const hash = hmac.digest('hex');
params.hash = hash;
const jsonString = JSON.stringify(params, null, 2);
console.log(jsonString);
Load Mini App via URL in Super App
Simple, flexible, native-like web applications to enhance user experience
URL Scheme to load
URL: {miniapp_domain}/?platform=seamless#seamlessAuth={seamlessAuth}
Parameter name | Data Type | Mandatory | Description |
---|---|---|---|
miniapp_domain | String | Yes | Provided to you on your N11s Back Office |
seamlessAuth | String | Yes | A string with raw data transferred to the Mini App, convenient for validating data. This value must be encoded. Example: - Use Javascript: encodeURIComponent(initData) .- Use Go: url.QueryEscape(initData) |