def auth_uri(self, context, response_type, scope=None, state=None,
                 **kwargs):
        if state:
            context.state = state
        param = xdict(response_type=response_type,
                      client_id=self.client.client_id,
                      redirect_uri=self.client.redirect_uri,
                      scope=scope,
                      state=context.state)
        for k in kwargs:
            param[k] = kwargs[k]

        self._call_hook('auth_uri_customize_hook', context, param)

        p = urlencode(param.to_dict())
        rv = self.server.authorization_endpoint + '?' + p
        return rv
    def _get_token_from_token_endpoint(self, context, param):
        cred = None
        p = xdict(grant_type='authorization_code',
                  code=param['code'],
                  redirect_uri=self.client.redirect_uri)
        methods = self.server.token_endpoint_auth_methods_supported
        if 'client_secret_basic' in methods:
            cred = (self.client.client_id, self.client.client_secret)
        elif 'client_secret_post' in methods:
            p['client_id'] = self.client.client_id
            p['client_secret'] = self.client.client_secret
        else:
            raise OAuth2UnsupportedAuthMethodError()

        r = urlopen(self.server.token_endpoint, urlencode(p), basic_auth=cred)
        d = json.loads(r.read())

        param.clear()
        param.update(d)