没有秘密的角度jwt解码我的JWT怎么样? [英] How is angular-jwt decoding my JWT without a secret?

查看:259
本文介绍了没有秘密的角度jwt解码我的JWT怎么样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Auth0团队创建了一个名为angular-jwt的内容,它具有一个jwtHelper类。这个东西成功地解码了一个本地的JWT,没有我在服务器上使用的秘密。这怎么发生的?如果他们不安全,那么使用秘密来签名/加密的点是什么?

The Auth0 team created something called "angular-jwt" which has a jwtHelper class. This thing successfully decodes a local JWT without the secret I used on the server. How did this happen? If they are not secure, then what is the point of using a secret to sign/encrypt them?

加密令牌的服务器上的功能(使用jsonwebtoken) :

Function on the server that encrypts the token (using "jsonwebtoken"):

function createToken (user) {
    return jwt.sign(_.omit(user, 'password'), config.secret, { expiresInMinutes: 60*5 });
}

客户端的代码:

angular
    .module('sample.home', [
        'ui.router',
        'angular-storage',
        'angular-jwt'
    ])
    .config(function ($stateProvider) {
        $stateProvider
            .state('home', {
                url: '/',
                controller: 'HomeCtrl',
                templateUrl: 'modules/home/home.html',
                data: { requiresLogin: true }
            })
    })
    .controller('HomeCtrl', function homeController ($scope, $http, store, jwtHelper) {

        $scope.jwt = store.get('jwt');
        $scope.decodedJwt = $scope.jwt && jwtHelper.decodeToken($scope.jwt);

    });

以下是完整示例的链接: http://github.com/auth0/ang ...

Here's a link to the full example: http://github.com/auth0/ang...

推荐答案

JWT使用编码而不是加密。令牌包含的数据不是秘密,任何人都可以解码并查看。使用秘密(在您的情况下, config.secret )签署令牌,这有效地使得无法修改令牌而不知道该秘密。因此,只有服务器能够更改令牌的内容,但任何人都可以读取它。

A JWT uses encoding, not encryption. The data that the token contains is not a secret, anyone can decode it and view. What the server does, is it signs the token using a secret (in your case, config.secret), which effectively makes it impossible to modify the token without knowing the secret. Hence, only the server will be able to change the contents of the token, but anyone can read it.

这篇关于没有秘密的角度jwt解码我的JWT怎么样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆