예제 #1
0
파일: oauth2.py 프로젝트: mhellmic/b2share
    def _get_user_email_and_id(container, req):
        """
        Returns external identity and email address together. Since identity is
        essential for OAuth2 authentication, if it doesn't find external
        identity returns None, None.

        @param container: container which contains email and id
        @type container: list|dict

        @rtype str|NoneType, str|NoneType
        """
        from invenio.modules.access.local_config import CFG_OAUTH2_CONFIGURATIONS

        identity = None
        email = None

        #if req.g['oauth2_provider_name'] == 'orcid':


        if 'id' in CFG_OAUTH2_CONFIGURATIONS[req.g['oauth2_provider_name']]:
            path = CFG_OAUTH2_CONFIGURATIONS[req.g['oauth2_provider_name']]['id']
            identity = get_substructure(container, path)

        if identity:
            if 'email' in CFG_OAUTH2_CONFIGURATIONS[req.g['oauth2_provider_name']]:
                path = CFG_OAUTH2_CONFIGURATIONS[req.g['oauth2_provider_name']]\
                    ['email']
                email = get_substructure(container, path)

            req.g['oauth2_response'] = container

        return email, identity
예제 #2
0
    def _get_user_email_and_id(self, container, req):
        """
        Returns external identity and email address together. Since identity is
        essential for OAuth1 authentication, if it doesn't find external
        identity returns None, None.

        @param container: container which contains email and id
        @type container: list|dict

        @rtype str|NoneType, str|NoneType
        """
        from invenio.modules.access.local_config import CFG_OAUTH1_CONFIGURATIONS

        identity = None
        email = None

        if 'id' in CFG_OAUTH1_CONFIGURATIONS[req.g['oauth1_provider_name']]:
            path = CFG_OAUTH1_CONFIGURATIONS[
                req.g['oauth1_provider_name']]['id']
            identity = get_substructure(container, path)

        if identity:
            if 'email' in CFG_OAUTH1_CONFIGURATIONS[
                    req.g['oauth1_provider_name']]:
                path = CFG_OAUTH1_CONFIGURATIONS[
                    req.g['oauth1_provider_name']]['email']
                email = get_substructure(container, path)

            req.g['oauth1_response'] = container

        return email, identity
예제 #3
0
파일: oauth2.py 프로젝트: mhellmic/b2share
    def fetch_user_nickname(self, username, password=None, req=None):
        """
        Fetches the OAuth2 provider for nickname of the user. If it doesn't
            find any, returns None.

        This function doesn't need username, password or req. They are exist
            just because this class is derived from ExternalAuth

        @param username: Isn't used in this function
        @type username: str

        @param password: Isn't used in this function
        @type password: str

        @param req: Isn't used in this function
        @type req: invenio.legacy.wsgi.SimulatedModPythonRequest

        @rtype: str or NoneType
        """
        from invenio.modules.access.local_config import CFG_OAUTH2_CONFIGURATIONS

        if req.g['oauth2_provider_name'] and req.g['oauth2_response']:
            path = None
            if 'nickname' in CFG_OAUTH2_CONFIGURATIONS[req.g['oauth2_provider_name']]:
                path = CFG_OAUTH2_CONFIGURATIONS[req.g['oauth2_provider_name']]['nickname']

            if path:
                return get_substructure(req.g['oauth2_response'], path)
        else:
            return None
예제 #4
0
    def fetch_user_nickname(self, username, password=None, req=None):
        """
        Fetches the OAuth1 provider for nickname of the user. If it doesn't
            find any, returns None.

        This function doesn't need username, password or req. They are exist
            just because this class is derived from ExternalAuth

        @param username: Isn't used in this function
        @type username: str

        @param password: Isn't used in this function
        @type password: str

        @param req: Isn't used in this function
        @type req: invenio.legacy.wsgi.SimulatedModPythonRequest

        @rtype: str or NoneType
        """
        from invenio.modules.access.local_config import CFG_OAUTH1_CONFIGURATIONS

        if req.g['oauth1_provider_name']:
            path = None
            if 'nickname' in CFG_OAUTH1_CONFIGURATIONS[
                    req.g['oauth1_provider_name']]:
                path = CFG_OAUTH1_CONFIGURATIONS[
                    req.g['oauth1_provider_name']]['nickname']

            if path:
                return get_substructure(req.oauth1_response, path)
        else:
            return None