Revision d2104099

b/astakosclient/astakosclient/__init__.py
39 39
import urlparse
40 40
import urllib
41 41
import hashlib
42
from base64 import b64encode
42 43
from copy import copy
43 44

  
44 45
import simplejson
......
144 145
        self._ui_prefix = parsed_ui_url.path
145 146
        self.logger.debug("Got ui_prefix \"%s\"" % self._ui_prefix)
146 147

  
148
        oa2_service_catalog = parse_endpoints(endpoints, ep_name="astakos_oa2")
149
        self._oa2_url = \
150
            oa2_service_catalog[0]['endpoints'][0]['publicURL']
151
        parsed_oa2_url = urlparse.urlparse(self._oa2_url)
152
        self._oa2_prefix = parsed_oa2_url.path
153

  
147 154
    def _get_value(self, s):
148 155
        assert s in ['_account_url', '_account_prefix',
149
                     '_ui_url', '_ui_prefix']
156
                     '_ui_url', '_ui_prefix',
157
                     '_oa2_url', '_oa2_prefix']
150 158
        try:
151 159
            return getattr(self, s)
152 160
        except AttributeError:
......
170 178
        return self._get_value('_ui_prefix')
171 179

  
172 180
    @property
181
    def oa2_url(self):
182
        return self._get_value('_oa2_url')
183

  
184
    @property
185
    def oa2_prefix(self):
186
        return self._get_value('_oa2_prefix')
187

  
188
    @property
173 189
    def api_usercatalogs(self):
174 190
        return join_urls(self.account_prefix, "user_catalogs")
175 191

  
......
217 233
    def api_getservices(self):
218 234
        return join_urls(self.ui_prefix, "get_services")
219 235

  
236
    @property
237
    def api_oa2_auth(self):
238
        return join_urls(self.oa2_prefix, "auth")
239

  
240
    @property
241
    def api_oa2_token(self):
242
        return join_urls(self.oa2_prefix, "token")
243

  
220 244
    # ----------------------------------
221 245
    @retry_dec
222 246
    def _call_astakos(self, request_path, headers=None,
......
877 901
        return self._call_astakos(self.api_memberships, headers=req_headers,
878 902
                                  body=req_body, method="POST")
879 903

  
904
    # --------------------------------
905
    # do a POST to ``API_OA2_TOKEN``
906
    def get_token(self, grant_type, client_id, client_secret, **body_params):
907
        headers = {'Content-Type': 'application/x-www-form-urlencoded',
908
                   'Authorization': 'Basic %s' % b64encode('%s:%s' %
909
                                                           (client_id,
910
                                                            client_secret))}
911
        body_params['grant_type'] = grant_type
912
        body = urllib.urlencode(body_params)
913
        return self._call_astakos(self.api_oa2_token, headers=headers,
914
                                  body=body, method="POST")
915

  
880 916

  
881 917
# --------------------------------------------------------------------
882 918
# parse endpoints

Also available in: Unified diff