예제 #1
0
    def test_get_authentication_failed_url_returns_expected_url(self):
        # Act
        auth_failed_url = AuthenticationService.get_authentication_failed_url()

        # Assert
        parsed_url = urlparse(auth_failed_url)
        self.assertEqual(parsed_url.path, '/auth-failed')
예제 #2
0
    def get(self):
        """
        Handles the OSM OAuth callback
        ---
        tags:
          - authentication
        produces:
          - application/json
        responses:
          302:
            description: Redirects to login page, or login failed page
          500:
            description: A problem occurred authenticating the user
          502:
            description: A problem occurred negotiating with the OSM API
        """
        osm_resp = osm.authorized_response()
        if osm_resp is None:
            current_app.logger.critical('No response from OSM')
            return redirect(
                AuthenticationService.get_authentication_failed_url())
        else:
            session[
                'osm_oauth'] = osm_resp  # Set OAuth details in the session temporarily

        osm_response = osm.request(
            'user/details')  # Get details for the authenticating user

        if osm_response.status != 200:
            current_app.logger.critical('Error response from OSM')
            return redirect(
                AuthenticationService.get_authentication_failed_url())

        try:
            redirect_to = request.args.get('redirect_to')
            authorized_url = AuthenticationService.login_user(
                osm_response.data, redirect_to)
            return redirect(
                authorized_url
            )  # Redirect to Authentication page on successful authorization :)
        except AuthServiceError as e:
            return {"Error": str(e)}, 500