Beispiel #1
0
    def get(self, request, Format=None):
        logger.info('-' * 100)
        logger.info('Reddit Oauth request =>')

        # Create a valid state integer and save it to cache
        state = Utils.save_valid_state_in_cache('oauth')
        logger.debug(f'Saving oauth_{state} in cache with status pending')

        # Obtain authorization URL
        reddit = reddit = Utils.get_reddit_instance()
        # scopes = ['*'] All OAuth scopes available
        scopes = [
            'edit',
            'history',
            'identity',
            'mysubreddits',
            'read',
            'submit',
            'subscribe',
            'vote',
        ]
        auth_url = reddit.auth.url(scopes, state)
        logger.debug(f'Reddit auth url: {auth_url}')

        return Response({
            'oauth_url': auth_url,
            'state': state
        },
                        status=status.HTTP_200_OK)
Beispiel #2
0
    def get(self, request, Format=None):
        logger.info('-' * 100)
        logger.info('Client Salesforce OAuth request =>')

        # Get the org_id from the request, I need to save it in cache because the callback
        # cannnot have a Bearer token Authorization header
        client_org = request.user
        # Save valid state integer in cache with the org_id linked to the client_org
        state = Utils.save_valid_state_in_cache('salesforce_oauth',
                                                client_org.salesforce_org_id)
        logger.debug(
            f'Saving salesforce_oauth_{state} in cache with status pending')

        oauth_url = Utils.make_url_with_params(
            self.endpoint_url,
            response_type='code',
            client_id=self.client_id,
            prompt='consent',
            redirect_uri=self.redirect_uri,
            scope='full refresh_token',
            state=state,
        )
        return Response({
            'oauth_url': oauth_url,
            'state': state
        },
                        status=status.HTTP_200_OK)