示例#1
0
文件: oauth.py 项目: zhill/quay
    def discard_authorization_code(self, client_id, full_code):
        code_name = full_code[:AUTHORIZATION_CODE_PREFIX_LENGTH]
        try:
            found = (
                OAuthAuthorizationCode.select().join(OAuthApplication).where(
                    OAuthApplication.client_id == client_id,
                    OAuthAuthorizationCode.code_name == code_name,
                ).get())
            found.delete_instance()
            return
        except OAuthAuthorizationCode.DoesNotExist:
            pass

        # Legacy: full code.
        # TODO(remove-unenc): Remove legacy fallback.
        if ActiveDataMigration.has_flag(ERTMigrationFlags.READ_OLD_FIELDS):
            try:
                found = (OAuthAuthorizationCode.select().join(
                    OAuthApplication).where(
                        OAuthApplication.client_id == client_id,
                        OAuthAuthorizationCode.code == full_code,
                    ).get())
                found.delete_instance()
            except OAuthAuthorizationCode.DoesNotExist:
                pass
示例#2
0
文件: oauth.py 项目: zhill/quay
    def from_authorization_code(self, client_id, full_code, scope):
        code_name = full_code[:AUTHORIZATION_CODE_PREFIX_LENGTH]
        code_credential = full_code[AUTHORIZATION_CODE_PREFIX_LENGTH:]

        try:
            found = (
                OAuthAuthorizationCode.select().join(OAuthApplication).where(
                    OAuthApplication.client_id == client_id,
                    OAuthAuthorizationCode.code_name == code_name,
                    OAuthAuthorizationCode.scope == scope,
                ).get())
            if not found.code_credential.matches(code_credential):
                return None

            logger.debug("Returning data: %s", found.data)
            return found.data
        except OAuthAuthorizationCode.DoesNotExist:
            # Fallback to the legacy lookup of the full code.
            # TODO(remove-unenc): Remove legacy fallback.
            if ActiveDataMigration.has_flag(ERTMigrationFlags.READ_OLD_FIELDS):
                try:
                    found = (OAuthAuthorizationCode.select().join(
                        OAuthApplication).where(
                            OAuthApplication.client_id == client_id,
                            OAuthAuthorizationCode.code == full_code,
                            OAuthAuthorizationCode.scope == scope,
                        ).get())
                    logger.debug("Returning data: %s", found.data)
                    return found.data
                except OAuthAuthorizationCode.DoesNotExist:
                    return None
            else:
                return None
示例#3
0
 def discard_authorization_code(self, client_id, full_code):
     code_name = full_code[:AUTHORIZATION_CODE_PREFIX_LENGTH]
     try:
         found = (
             OAuthAuthorizationCode.select().join(OAuthApplication).where(
                 OAuthApplication.client_id == client_id,
                 OAuthAuthorizationCode.code_name == code_name,
             ).get())
         found.delete_instance()
         return
     except OAuthAuthorizationCode.DoesNotExist:
         pass
示例#4
0
    def from_authorization_code(self, client_id, full_code, scope):
        code_name = full_code[:AUTHORIZATION_CODE_PREFIX_LENGTH]
        code_credential = full_code[AUTHORIZATION_CODE_PREFIX_LENGTH:]

        try:
            found = (
                OAuthAuthorizationCode.select().join(OAuthApplication).where(
                    OAuthApplication.client_id == client_id,
                    OAuthAuthorizationCode.code_name == code_name,
                    OAuthAuthorizationCode.scope == scope,
                ).get())
            if not found.code_credential.matches(code_credential):
                return None

            logger.debug("Returning data: %s", found.data)
            return found.data
        except OAuthAuthorizationCode.DoesNotExist:
            return None