index.d.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { IgnoreOrMatch } from 'egg';
  2. import { SignOptions, SignCallback, VerifyOptions, VerifyCallback } from 'jsonwebtoken';
  3. declare module 'egg' {
  4. interface Application {
  5. jwt: {
  6. /**
  7. * call jsonwebtoken's sign() method
  8. * @param payload datas. datas to be signed
  9. * @param secretOrPrivateKey secret key. string or { key, passphrase }
  10. * @param options jwt options。see more details in https://github.com/auth0/node-jsonwebtoken
  11. * @param callback callback
  12. */
  13. sign(
  14. payload: string | Buffer | object,
  15. secretOrPrivateKey: string,
  16. options?: SignOptions,
  17. callback?: SignCallback
  18. ): string;
  19. /**
  20. * call jsonwebtoken's verify() method
  21. * @param token jwt token.
  22. * @param secretOrPrivateKey secret key。string or { key, passphrase }
  23. * @param options jwt options。see more details in https://github.com/auth0/node-jsonwebtoken
  24. * @param callback callback
  25. */
  26. verify(token: string, secretOrPrivateKey: string, options?: VerifyOptions, callback?: VerifyCallback): string;
  27. /**
  28. * call jsonwebtoken's decode() method
  29. * @param token jwt token
  30. */
  31. decode(token: string): string;
  32. };
  33. }
  34. interface EggAppConfig {
  35. jwt: {
  36. secret: string;
  37. enable?: boolean;
  38. sign?: SignOptions;
  39. verify?: VerifyOptions;
  40. ignore?: IgnoreOrMatch;
  41. match?: IgnoreOrMatch;
  42. };
  43. }
  44. }