首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在与Auth0一起使用JWKS时,如果我使用本地主机,那么听众和发行者是什么?

在与Auth0一起使用JWKS时,如果我使用本地主机,那么听众和发行者是什么?
EN

Stack Overflow用户
提问于 2019-05-01 04:58:47
回答 1查看 596关注 0票数 0

我在Node应用程序中实现了JWT:

代码语言:javascript
复制
import Router from 'koa-router-middleware';
import { ApplicationState, ApplicationContext } from './types';
import configure from './configure';
import swagger from './swagger';
import healthcheck from './healthcheck';
import helloworld from './helloworld';
const jwt = require('jsonwebtoken');
// import * as jwt from 'jsonwebtoken'; << TODO
import * as koajwt from 'koa-jwt';

export default new Router<ApplicationState, ApplicationContext>()
  .use(configure)
  .use('/openapi.json', swagger)
  .use('/', helloworld)
  .use('/healthcheck', healthcheck)
  .use('/token', (ctx) => {
    const token = jwt.sign({ data: 'tokenData' }, 'secret');
    ctx.response.body = token;
  })
  // Secure routes
  .use(koajwt({ secret: 'secret' }))
  .use('/secure', helloworld)
  .middleware();

现在,我试图让它与Auth0一起工作,所以我研究了JWKS,下面是我所拥有的:

代码语言:javascript
复制
import Router from 'koa-router-middleware';
import { ApplicationState, ApplicationContext } from './types';
import configure from './configure';
import swagger from './swagger';
import healthcheck from './healthcheck';
import helloworld from './helloworld';
// const jsonwebtoken = require('jsonwebtoken');
// import * as jwt from 'jsonwebtoken'; << TODO
import * as jwt from 'koa-jwt';
const jwksRsa = require('jwks-rsa');

const jwksHost = 'omitted'
const audience = 'http://localhost:8080'
const issuer = '??'

export default new Router<ApplicationState, ApplicationContext>()
  .use(configure)
  .use('/openapi.json', swagger)
  .use('/', helloworld)
  .use('/healthcheck', healthcheck)
  .use(jwt({
    secret: jwksRsa.koaJwtSecret({
      cache: true,
      rateLimit: true,
      jwksRequestsPerMinute: 2,
      jwksUri: `${jwksHost}/.well-known/jwks.json`
    }),
    audience,
    issuer,
    algorithms: [ 'RS256' ]
  }))

  // Secure routes. Anything below this comment needs a jwt token
  .use('/secure', helloworld)
  .middleware();

第一个问题:我可以在本地主机上这样做吗?或者我必须上传代码才能工作?

第二个问题:我使用的是Auth0在我创建帐户时分配给我的JWKS端点,假设每个帐户只有一个JWKS端点是否正确,即使该帐户有多个API?(在本网站上,它说每个租户有一个,我假设这意味着帐户,但我想确认)

第三个问题:除了观众和发行者之外,这段代码看上去是对的还是遗漏了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-29 12:30:19

看看的答案

看起来应该是:

代码语言:javascript
复制
audience: 'http://localhost:3000', // With your port
issuer: `https://${process.env.AUTH0_DOMAIN}/` // Your Auth0 domain
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55931805

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档