X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FNBI.git;a=blobdiff_plain;f=osm_nbi%2Fauthconn_keystone.py;h=9fff7929ff91deb746308170ccd4092a056d6602;hp=23b07e3bbb79426b7f42e74684f87bb472ad474a;hb=c844536bb27c39aa48988284c5a0d7b404930a8a;hpb=1f029d84b9597d3986a33dcd847b0d97d2bad077 diff --git a/osm_nbi/authconn_keystone.py b/osm_nbi/authconn_keystone.py index 23b07e3..9fff792 100644 --- a/osm_nbi/authconn_keystone.py +++ b/osm_nbi/authconn_keystone.py @@ -188,16 +188,30 @@ class AuthconnKeystone(Authconn): Check if the token is valid. :param token: token to validate - :return: dictionary with information associated with the token. If the - token is not valid, returns None. + :return: dictionary with information associated with the token: + "expires": + "_id": token_id, + "project_id": project_id, + "username": , + "roles": list with dict containing {name, id} + If the token is not valid an exception is raised. """ if not token: return try: token_info = self.keystone.tokens.validate(token=token) + ses = { + "_id": token_info["auth_token"], + "project_id": token_info["project"]["id"], + "project_name": token_info["project"]["name"], + "user_id": token_info["user"]["id"], + "username": token_info["user"]["name"], + "roles": token_info["roles"], + "expires": token_info.expires.timestamp() + } - return token_info + return ses except ClientException as e: self.logger.exception("Error during token validation using keystone: {}".format(e)) raise AuthException("Error during token validation using Keystone: {}".format(e),