项目作者: kchung

项目描述 :
Command-line MapKit JS token generator
高级语言: JavaScript
项目地址: git://github.com/kchung/mapkitjs-token.git
创建时间: 2020-03-07T23:50:25Z
项目社区:https://github.com/kchung/mapkitjs-token

开源协议:MIT License

下载


MapKit JS Token Generator

semantic-release: conventionalcommits
NPM Version

Generate long-lived tokens from the CLI that can be used with the MapKit JS’s authorizationCallback.

Setting authorizationCallback to a function that returns a token as a string is useful for local development, or if you want to use a long-lived token with MapKit JS. Sign a token locally on your development machine with an expiration, then use the token directly in your code.

  1. mapkit.init({
  2. authorizationCallback(done) {
  3. done('your-generated-token-string-here');
  4. },
  5. });

Features

  • Verifies if the token works against MapKit servers

Usage

  1. $ npx mapkitjs-token [options]

Since we’re dealing with private keys, you may feel safer compiling this tool yourself and running it locally (see Compiling).

Options

  1. Options:
  2. --help Show help [boolean]
  3. --version Show version number [boolean]
  4. --kid A 10-character key identifier (kid) key, obtained from your Apple
  5. Developer account [string] [required]
  6. --iss The Issuer (iss) registered claim key. This key's value is your
  7. 10-character Team ID, obtained from your developer account.
  8. [string] [required]
  9. --iat The Issued At (iat), relative to now. Uses `zeit/ms` strings (e.g
  10. '0', '2d', '1y')
  11. [string] [default: 0, current time (e.g 0 seconds from "now")]
  12. --exp The Expiration Time (exp) relative to `iat`, using a `zeit/ms`
  13. string (e.g '1hr, '2d', '1y').
  14. [string] [default: 364d, 364 day expiration]
  15. --sub The subject public claim key. This value could for example be your
  16. registered Service ID. Needed for WeatherKit tokens.
  17. [string]
  18. --key MapKit private key file path [required]
  19. --origin The Origin (origin) key. This key's value is a fully qualified
  20. domain that should match the Origin header passed by a browser.
  21. [string]
  22. --verify Test the generated token with MapKit servers to verify if valid
  23. [boolean] [default: true, will verify token after it generates]
  24. --stdout Set to true to output only the token, suitable for piping
  25. [boolean] [default: false, by default, outputs extra data about the token]

See the MapKit JS documentation for the full explanation of these options.

Examples

Generate a token with the default expiration (1 year) and verify the token works:

  1. $ npx mapkitjs-token --kid ABC123DEFG --iss DEF123GHIJ --key ./secret.p8
  2. Token Information:
  3. Key Id (kid) ABC123DEFG
  4. Issuer (iss) DEF123GHIJ
  5. Issued (iat) 1583626697 (Sat Mar 07 2020 16:18:17 GMT-0800 (Pacific Standard Time))
  6. Expire (exp) 1583630297 (Sat Mar 07 2020 17:18:17 GMT-0800 (Pacific Standard Time))
  7. Expires In 364 days (31449600s)
  8. Sub none
  9. Origin none
  10. Valid valid
  11. Token [generated token]

Generate a token to stdout, verify, and copy directly to clipboard (macOS via pbcopy):

  1. $ npx mapkitjs-token --kid ABC123DEFG --iss DEF123GHIJ --key ./secret.p8 --stdout | pbcopy

Generate a token with a 8 year expiration, add an origin, and skip verification:

  1. $ npx mapkitjs-token --kid ABC123DEFG --iss DEF123GHIJ --key ./secret.p8 --exp=8y --origin https://example.com --verify=false
  2. Token Information:
  3. Key Id (kid) ABC123DEFG
  4. Issuer (iss) DEF123GHIJ
  5. Issued (iat) 1583627770 (Sat Mar 07 2020 16:36:10 GMT-0800 (Pacific Standard Time))
  6. Expire (exp) 1836088570 (Tue Mar 07 2028 16:36:10 GMT-0800 (Pacific Standard Time))
  7. Expires In 2922 days (252460800s)
  8. Sub none
  9. Origin https://example.com
  10. Valid skipped
  11. Token [generated token]

Compiling

  1. $ npm ci
  2. $ npm run build
  3. $ node ./dist/cli.js [options]