Skip to content

Application Keys

Billcountry Mwaniki edited this page Aug 30, 2020 · 1 revision

Application Keys are used to authorize ops from API/RPC requests. Application Keys are immutable and hold permissions less than or equal to those of the user who created them. Keys can have multiple tokens and a token can be removed or all tokens invalidated by invalidating a key.

Structure:

  • KeyId primitive.ObjectId
  • AppUserId primitive.ObjectId The user who created the key
  • ApplicationId primitive.ObjectId The application the key belongs to. We can get the same from a user but it's one less database call
  • Permissions []uint8 A list of permissions this key can access. You can get values of permissions from Users
  • Status uint8 Status of the app including
    • Active: 0
    • Revoked: 1
    • Archived: 2
  • Tokens []Token A list of JWT tokens that can be used to authorize as this key. A Token has the structure below:
    • Id primitive.ObjectId Unique identifier to a token
    • Issued int64 Unix timestamp of when the token was issued
    • Expiry int64 Unix timestamp of when the token expires
  • Created Time

Methods

Key.CreateToken(expiry Time) -> String

Creates a new token, adds it to the Tokens list and returns a JWT token string that can be used to authorize the key.

Key.HasToken(id primitive.ObjectId) -> bool

Check if a token has a specific key. This should be used to reject deleted tokens.

Clone this wiki locally