Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 在spring boot中使用Outh服务器uri验证nodejs资源服务器中的访问令牌 我有OAuth2服务器[Spring boot],它使用密码凭据方法验证客户端 前端客户端[Vuejs]获得的访问令牌使用该令牌访问资源服务器[Spring boot]_Node.js_Spring Boot_Oauth 2.0 - Fatal编程技术网

Node.js 在spring boot中使用Outh服务器uri验证nodejs资源服务器中的访问令牌 我有OAuth2服务器[Spring boot],它使用密码凭据方法验证客户端 前端客户端[Vuejs]获得的访问令牌使用该令牌访问资源服务器[Spring boot]

Node.js 在spring boot中使用Outh服务器uri验证nodejs资源服务器中的访问令牌 我有OAuth2服务器[Spring boot],它使用密码凭据方法验证客户端 前端客户端[Vuejs]获得的访问令牌使用该令牌访问资源服务器[Spring boot],node.js,spring-boot,oauth-2.0,Node.js,Spring Boot,Oauth 2.0,在这里,当前端客户端将访问令牌传递给资源服务器时,资源服务器使用以下代码与OAuth2服务器交叉验证它 @配置 @EnableResourceServer 公共类OAuth2ResourceServerConfigRemoteTokenService扩展了ResourceServerConfigurerAdapter{ @初级的 @豆子 公共远程令牌服务令牌服务(){ final RemoteTokenServices tokenService=新的RemoteTokenServices();

在这里,当前端客户端将访问令牌传递给资源服务器时,资源服务器使用以下代码与OAuth2服务器交叉验证它

@配置
@EnableResourceServer
公共类OAuth2ResourceServerConfigRemoteTokenService扩展了ResourceServerConfigurerAdapter{
@初级的
@豆子
公共远程令牌服务令牌服务(){
final RemoteTokenServices tokenService=新的RemoteTokenServices();
tokenService.setCheckTokenEndpointUrl(“https://localhost:9088/oauth/check_token");
setClientId(“fooclientdpassword”);
tokenService.setClientSecret(“密码”);
返回令牌服务;
}
}

  • 现在,我正试图用nodejs实现同样的功能,因为我计划拆分一个特定的功能,这会给springboot中编写的资源服务器带来开销

  • 我不知道如何在NodeJ中实现交叉验证机制,如下面的代码


  • tokenService.setCheckTokenEndpointUrl(“https://localhost:9088/oauth/check_token");

    尝试express-oauth2-bearer库,它工作正常 首先,安装它: npm i express-oauth2-bearier—保存 并在客户端中使用此代码: 库需要以下值来验证请求:

    • 颁发者基本URL:授权服务器的基本URL。如果您使用的是Auth0,则这是您的租户
      https://
      (如
      https://tenant.auth0.com
      )可在中应用程序的设置选项卡上找到
    • 允许的访问群体:访问令牌允许的访问群体标识符(或由逗号分隔的多个标识符)。如果您使用的是Auth0,则这是在中的API设置选项卡上找到的标识符
    可以在应用程序根目录中的
    .env
    文件中配置:

    # .env
    
    ISSUER_BASE_URL=https://YOUR_DOMAIN
    ALLOWED_AUDIENCES=https://api.yourapplication.com
    
    。。。或者在您的应用程序代码中:

    app.use(auth({
    发行人背景:'https://tenant.auth0.com',
    允许观众:'https://api.yourapplication.com'
    }));
    
    OpenID策略是令牌验证的默认策略。使用
    .env
    文件中设置的配置值,以下代码将所有正在进行的路由的请求限制为具有
    https://api.yourapplication.com
    受众和
    阅读:产品
    范围:

    const{auth,requiredScopes}=require('express-oauth2-bearer');
    app.use(auth());
    app.get(“/products”,
    所需范围(“读取:产品”),
    (请求、回复)=>{
    console.dir(请求授权声明);
    res.sendStatus(200);
    });
    
    如果访问令牌不希望像OpenID Connect ID令牌那样进行签名,请添加带有回调的
    auth
    中间件以进行验证,如下所示:

    const{auth,requiredScopes}=require('express-oauth2-bearer');
    const validateAccesToken=异步(令牌)=>{
    const token=wait db.tokens.find(令牌);
    if(token.expired){return;}
    返回令牌;
    };
    app.use(auth(validateAccessToken));
    app.get(“/products”,
    所需范围(“读取:产品”),
    (请求、回复)=>{
    console.dir(请求授权声明);
    res.sendStatus(200);
    });