本文整理汇总了Python中jwkest.jwk.SYMKey方法的典型用法代码示例。如果您正苦于以下问题:Python jwk.SYMKey方法的具体用法?Python jwk.SYMKey怎么用?Python jwk.SYMKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jwkest.jwk
的用法示例。
在下文中一共展示了jwk.SYMKey方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_client_alg_keys
# 需要导入模块: from jwkest import jwk [as 别名]
# 或者: from jwkest.jwk import SYMKey [as 别名]
def get_client_alg_keys(client):
"""
Takes a client and returns the set of keys associated with it.
Returns a list of keys.
"""
if client.jwt_alg == 'RS256':
keys = []
for rsakey in RSAKey.objects.all():
keys.append(jwk_RSAKey(key=importKey(rsakey.key), kid=rsakey.kid))
if not keys:
raise Exception('You must add at least one RSA Key.')
elif client.jwt_alg == 'HS256':
keys = [SYMKey(key=client.client_secret, alg=client.jwt_alg)]
else:
raise Exception('Unsupported key algorithm.')
return keys
示例2: create_jwt
# 需要导入模块: from jwkest import jwk [as 别名]
# 或者: from jwkest.jwk import SYMKey [as 别名]
def create_jwt(self, user):
"""
Creates a signed (JWS) ID token.
Returns:
str: JWS
"""
key = SYMKey(key=self.site.siteconfiguration.oauth_settings['SOCIAL_AUTH_EDX_OAUTH2_SECRET'])
now = datetime.datetime.utcnow()
expiration_datetime = now + datetime.timedelta(seconds=3600)
issue_datetime = now
payload = {
'iss': self.site.siteconfiguration.lms_url_root,
'administrator': False,
'iat': timegm(issue_datetime.utctimetuple()),
'sub': str(uuid.uuid4()),
'preferred_username': user.username,
'aud': self.site.siteconfiguration.oauth_settings['SOCIAL_AUTH_EDX_OAUTH2_KEY'],
'exp': timegm(expiration_datetime.utctimetuple()),
}
access_token = JWS(payload, jwk=key, alg='HS512').sign_compact()
return access_token
示例3: signed_id_token
# 需要导入模块: from jwkest import jwk [as 别名]
# 或者: from jwkest.jwk import SYMKey [as 别名]
def signed_id_token(claims):
id_token = IdToken(**claims)
signing_key = SYMKey(alg='HS256', key=rndstr())
jws = id_token.to_jwt(key=[signing_key], algorithm=signing_key.alg)
return jws, signing_key
示例4: signing_keys
# 需要导入模块: from jwkest import jwk [as 别名]
# 或者: from jwkest.jwk import SYMKey [as 别名]
def signing_keys(self):
if self.signing_alg == self.RS256:
# TODO perform caching, OBVIOUS
return load_jwks_from_url(self.jwks_uri)
return [SYMKey(key=str(self.client_secret))]