Debian Codegraph @

keystoneclient/v3/contrib/federation/saml.py

raw symbols SCIP
1 # Licensed under the Apache License, Version 2.0 (the "License"); you may
2 # not use this file except in compliance with the License. You may obtain
3 # a copy of the License at
4 #
5 # http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 # License for the specific language governing permissions and limitations
11 # under the License.
12
13 from keystoneclient import base
14
15
16 SAML2_ENDPOINT = '/auth/OS-FEDERATION/saml2'
17 ECP_ENDPOINT = '/auth/OS-FEDERATION/saml2/ecp'
18
19
20 class SamlManager(base.Manager):
21 """Manager class for creating SAML assertions."""
22
23 def create_saml_assertion(self, service_provider, token_id):
24 """Create a SAML assertion from a token.
25
26 Equivalent Identity API call:
27 POST /auth/OS-FEDERATION/saml2
28
29 :param service_provider: Service Provider resource.
30 :type service_provider: string
31 :param token_id: Token to transform to SAML assertion.
32 :type token_id: string
33
34 :returns: SAML representation of token_id
35 :rtype: string
36 """
37 headers, body = self._create_common_request(service_provider, token_id)
38 resp, body = self.client.post(SAML2_ENDPOINT, json=body,
39 headers=headers)
40 return self._prepare_return_value(resp, resp.text)
41
42 def create_ecp_assertion(self, service_provider, token_id):
43 """Create an ECP wrapped SAML assertion from a token.
44
45 Equivalent Identity API call:
46 POST /auth/OS-FEDERATION/saml2/ecp
47
48 :param service_provider: Service Provider resource.
49 :type service_provider: string
50 :param token_id: Token to transform to SAML assertion.
51 :type token_id: string
52
53 :returns: SAML representation of token_id, wrapped in ECP envelope
54 :rtype: string
55 """
56 headers, body = self._create_common_request(service_provider, token_id)
57 resp, body = self.client.post(ECP_ENDPOINT, json=body,
58 headers=headers)
59 return self._prepare_return_value(resp, resp.text)
60
61 def _create_common_request(self, service_provider, token_id):
62 headers = {'Content-Type': 'application/json'}
63 body = {
64 'auth': {
65 'identity': {
66 'methods': ['token'],
67 'token': {
68 'id': token_id
69 }
70 },
71 'scope': {
72 'service_provider': {
73 'id': base.getid(service_provider)
74 }
75 }
76 }
77 }
78
79 return (headers, body)