def access_token_url(self): base_url = super(MITOAuth2, self).access_token_url() params = { 'grant_type': 'authorization_code', 'code': self.data['code'], 'redirect_uri': self.get_redirect_uri() } return url_add_parameters(base_url, params)
def get_redirect_uri(self, state=None): """Build redirect with redirect_state parameter.""" if state is not None: uri = self.blank_redirect_uri if self.REDIRECT_STATE and state: uri = url_add_parameters(uri, {'redirect_state': state}) else: uri = self.redirect_uri return uri
def get_redirect_uri(self, state=None): # TODO: Temporary solution to keep the same redirect uris as with the old allauth system try: custom_path = reverse('social:complete_{}_adfs'.format(self.realm)) uri = self.strategy.absolute_uri(custom_path) except NoReverseMatch: uri = self.redirect_uri if self.REDIRECT_STATE and state: uri = url_add_parameters(uri, {'redirect_state': state}) return uri
def get_redirect_uri(self, state=None): # TODO: Temporary solution to keep the same redirect uris as with the old allauth system try: custom_path = reverse('social:complete_{}_adfs'.format(self.realm)) uri = self.strategy.absolute_uri(custom_path) except NoReverseMatch: uri = self.redirect_uri if self.REDIRECT_STATE and state: uri = url_add_parameters(uri, { 'redirect_state': state }) return uri
def do_auth(httpretty, start_url, auth_options, access_token_body): """ Mock all the relevant uris for auth Return the target url with the expected code, nonce, redirect uri and params """ complete_url = reverse("gateway:nhsid_complete") start_query = parse_qs(urlparse(start_url).query) target_url = auth_options.strategy.build_absolute_uri(complete_url) target_url = url_add_parameters(target_url, {"state": start_query["state"]}) # mock the authorization call and its redirect to the target_url httpretty.register_uri(httpretty.GET, start_url, status=301, location=target_url) httpretty.register_uri(httpretty.GET, target_url, status=200, body="foobar") # Mock the JWK keys request (used to validate JWT id_token); JWK_PUBLIC_KEYS includes # the real key and an unsupported one to ensure we can deal with unsupported keys httpretty.register_uri( httpretty.GET, auth_options.backend.jwks_uri(), status=200, body=json.dumps({"keys": JWK_PUBLIC_KEYS}), ) # Mock the call to get the access token httpretty.register_uri( httpretty.POST, uri=auth_options.backend.access_token_url(), status=auth_options.access_token_status, body=json.dumps(access_token_body) or "", content_type="text/json", ) # Mock the call to the userinfo url httpretty.register_uri( httpretty.GET, auth_options.backend.userinfo_url(), body=json.dumps(auth_options.user_data_body) or "", content_type="text/json", ) return target_url
def get_redirect_uri(self, state=None): uri = self.redirect_uri if self.REDIRECT_STATE and state: uri = url_add_parameters(uri, {'state': state}) return uri