views.py 文件源码

python
阅读 66 收藏 0 点赞 0 评论 0

项目:authserver 作者: jdelic 项目源码 文件源码
def _make_access_token(self, request: HttpRequest, tokenreq: _TokenRequest,
                           rightnow: datetime.datetime, perms: TokenPermissions, for_user: MNUser) -> Dict[str, Any]:
        # TODO: figure out if we need to support more than one access scope
        # This implementation is based around this article, that, among other things,
        # describes the "kid" field required by Docker. The JWK implementation provided
        # by jwcrypto doesn't seem to work.
        # https://umbrella.cisco.com/blog/blog/2016/02/23/implementing-oauth-for-registry-v2/
        _x = []  # type: List[str]
        jwtobj = {
            'exp': int((rightnow + datetime.timedelta(minutes=2)).timestamp()),
            'nbf': int((rightnow - datetime.timedelta(seconds=1)).timestamp()),
            'iat': int(rightnow.timestamp()),
            'iss': request.get_host(),
            'aud': tokenreq.service,
            'sub': str(for_user.pk),
            'access': [{
                "type": perms.type,
                "name": perms.path,
                "actions": _x + (["push"] if perms.push else []) +
                                (["pull"] if perms.pull else []) +
                                (["login"] if perms.type == "login" else [])
            }]
        }  # type: Dict[str, Union[str, int, List[Dict[str, Union[str, List[str]]]]]]
        return jwtobj
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号