### Install jsonwebtoken for Node.js Source: https://open.teambition.com/docs/documents/5db8f7e77baeb50014957fc1 Installs the `jsonwebtoken` npm package, which is required for manually signing application access tokens. ```shell npm install jsonwebtoken ``` -------------------------------- ### Generate Application Access Token in Python Source: https://open.teambition.com/docs/documents/5db8f7e77baeb50014957fc1 Generates an application access token using the PyJWT library. The token includes expiration and issue time, and the application ID. Install with `pip install pyjwt`. ```python import jwt from datetime import datetime, timedelta secret_key = "your_secret_key_here" app_id = "your_app_id_here" # Create payload with expiration and issue time payload = { "exp": datetime.utcnow() + timedelta(hours=1), "iat": datetime.utcnow(), "_appId": app_id, } token = jwt.encode(payload, secret_key, algorithm="HS256") print(token) ``` -------------------------------- ### Initialize TWS for Node.js Source: https://open.teambition.com/docs/documents/5db8f7e77baeb50014957fc1 Initializes the TWS client for making API calls. This is a convenient way to handle application access tokens. ```javascript const { TWS } = require('tws-auth'); const tws = new TWS({ appId: '78f95e92c06a546f7dab7327', appSecrets: ['app_secret'], host: 'https://open.teambition.com/api' }); // Use tws to make calls ``` -------------------------------- ### Generate Application Access Token using JWT (Pseudocode) Source: https://open.teambition.com/docs/documents/5db8f7e77baeb50014957fc1 Provides pseudocode for generating an application access token with JWT. The payload must include `_appId`, `iat` (issue time), and `exp` (expiration time). ```bash header = {} payload = { _appId: "YOU_APP_ID", iat: NOW_SECOND, exp: NOW_SECOND + 3600 } jwt.sign(header, payload, "YOU_APP_SECRET") ``` -------------------------------- ### Generate Application Access Token in Golang Source: https://open.teambition.com/docs/documents/5db8f7e77baeb50014957fc1 Generates an application access token using the `jwt-go` library. The token includes expiration, issue time, and the application ID. ```go import ( "fmt" "github.com/dgrijalva/jwt-go" "time" ) func GenerateAppToken(appId string, secretKey string) (string, error) { token := jwt.New(jwt.SigningMethodHS256) claims := make(jwt.MapClaims) // Set expiration time to 1 hour from now claims["exp"] = time.Now().Add(time.Hour * time.Duration(1)).Unix() // Set issued at time claims["iat"] = time.Now().Unix() // Set application ID claim claims["_appId"] = appId token.Claims = claims tokenString, err := token.SignedString([]byte(secretKey)) if err != nil { return "", fmt.Errorf("failed to sign token: %w", err) } return tokenString, nil } ``` -------------------------------- ### Generate Application Access Token in Java Source: https://open.teambition.com/docs/documents/5db8f7e77baeb50014957fc1 Generates an application access token using JWT. Ensure the `java-jwt` library is included with version 3.4.0 or compatible. ```java import com.auth0.jwt.JWT; import com.auth0.jwt.algorithms.Algorithm; import java.util.Date; import org.springframework.util.StringUtils; public class AppTokenGenerator { public static final Long EXPIRES_IN = 1 * 3600 * 1000L; public static final String TOKEN_APPID = "_appId"; public static String genAppToken(String appId, String appSecret) { if (StringUtils.isEmpty(appId) || StringUtils.isEmpty(appSecret)) { return null; } Algorithm algorithm = Algorithm.HMAC256(appSecret); long timestamp = System.currentTimeMillis(); Date issuedAt = new Date(timestamp); Date expiresAt = new Date(timestamp + EXPIRES_IN); return JWT.create() .withClaim(TOKEN_APPID, appId) .withIssuedAt(issuedAt) .withExpiresAt(expiresAt) .sign(algorithm); } } ``` -------------------------------- ### Sign Application Access Token in Node.js Source: https://open.teambition.com/docs/documents/5db8f7e77baeb50014957fc1 Manually signs an application access token using `jsonwebtoken`. The token includes issue time, expiration, and the application ID. ```javascript const jwt = require('jsonwebtoken'); const appId = 'YOU_APP_ID'; // Replace with your Teambition Open Platform App ID const appSecret = 'YOU_APP_SECRET'; // Replace with your Teambition Open Platform App Secret const periodical = 3600; // Token validity period in seconds (1 hour) // Calculate issue time aligned to the period const iat = Math.floor(Date.now() / (1000 * periodical)) * periodical; // Payload including issue time, expiration, and app ID const payload = { iat, exp: iat + Math.floor(1.1 * periodical), // Expiration time (slightly longer than issue time) _appId: appId, }; // Sign the token with the app secret const token = jwt.sign(payload, appSecret); console.log(token); ``` -------------------------------- ### Add Java JWT Dependency Source: https://open.teambition.com/docs/documents/5db8f7e77baeb50014957fc1 Specifies the Maven dependency required for the `java-jwt` library. ```xml com.auth0 java-jwt 3.4.0 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.