代码之家  ›  专栏  ›  技术社区  ›  sakurashinken

如何以符合HIPAA的方式从gmail下载电子邮件?

  •  0
  • sakurashinken  · 技术社区  · 2 年前

    我有一个gmail工作区帐户,我想从中下载电子邮件,并将其加载到数据库中。这些电子邮件包含PHI(个人健康信息),因此必须始终按照合规标准进行加密。据我所知,启用TLS 1.2+的IMAP符合HIPAA标准。然而,当我试图设置这个时,我遇到了一些问题。

    1. 使用imaplib的直接请求会得到以下错误:

      (Pdb) imap_server.login('*****', '****')
      imaplib.IMAP4.error: b'[ALERT] Application-specific password required: 
      https://support.google.com/accounts/answer/185833 (Failure)'```
      
      
    2. 我不能创建应用程序密码,但必须使用gmailapi。如果我想使用IMAP进行连接,那么我需要向服务帐户授予全域权限,这对于所需的权限来说太大了,因为它可以访问组织中的所有电子邮件。

    3. 另一种选择是直接在帐户上发出oauth密钥,而不是创建服务帐户。这在实际意义上是可行的,但我不确定与我交互的API是否符合HIPAA。

    所以我的问题是,我如何以符合HIPAA的方式从谷歌工作区帐户下载电子邮件?带服务帐户的IMAP是我唯一的选择吗?

    0 回复  |  直到 2 年前
        1
  •  0
  •   Giselle Valladares    2 年前

    您可以使用OAuth对收件箱中的电子邮件下载进行身份验证和授权。此选项将创建 consent screen 在浏览器中,使用您的工作区帐户的电子邮件和密码授权下载电子邮件。

    sign-in consent screen

    你这样做是通过 creating a GCP project , enable the Google Workspace Gmail API ,设置您的 configure the OAuth consent screen ,创建并下载 OAuth client ID ,最后,您可以添加 authorization flow 在您的代码中。此流将根据您选择的编程语言而变化。

    python的E.g是:

    SCOPES = ['https://www.googleapis.com/auth/gmail.readonly']
    
    
    def main():
        
        creds = None
     
        if os.path.exists('token.json'):
            creds = Credentials.from_authorized_user_file('token.json', SCOPES)
    
        if not creds or not creds.valid:
            if creds and creds.expired and creds.refresh_token:
                creds.refresh(Request())
            else:
                flow = InstalledAppFlow.from_client_secrets_file(
                    'credentials.json', SCOPES)
                creds = flow.run_local_server(port=0)
    
            with open('token.json', 'w') as token:
                token.write(creds.to_json())
    

    您可以在Google文档中看到其他示例 here

    guides

    或者按照第三方应用程序的步骤,帮助您下载电子邮件。如果您使用Google OAuth,它应该符合HIPAA。但是,在共享或传输PHI之前,您有责任确保与任何第三方(或第三方应用程序、附加组件、系统或数据库)采取适当的符合HIPAA的措施。

        2
  •  0
  •   sakurashinken    2 年前

    事实证明,您可以使用应用程序密码。。。这个选项并不容易看到。

    https://myaccount.google.com/u/0/apppasswords 是打开它们的当前位置,即使使用组织帐户也是如此。因此,答案是使用TLS 1.2+和应用程序密码的IMAP是最简单的方法。