gpt4 book ai didi

outlook - 无法使用Office 365 REST API登录电子邮件

转载 作者:行者123 更新时间:2023-12-04 13:37:41 25 4
gpt4 key购买 nike

我按照这篇文章http://dev.office.com/code-samples-detail/2142和Ruby来获取用户的电子邮件地址。这是代码:

# Parses an ID token and returns the user's email
def get_email_from_id_token(id_token)

# JWT is in three parts, separated by a '.'
token_parts = id_token.split('.')
# Token content is in the second part
encoded_token = token_parts[1]

# It's base64, but may not be padded
# Fix padding so Base64 module can decode
leftovers = token_parts[1].length.modulo(4)
if leftovers == 2
encoded_token += '=='
elsif leftovers == 3
encoded_token += '='
end

# Base64 decode (urlsafe version)
decoded_token = Base64.urlsafe_decode64(encoded_token)

# Load into a JSON object
jwt = JSON.parse(decoded_token)

# Email is in the 'preferred_username' field
email = jwt['preferred_username']
end


这个功能很好用,我可以得到用户的电子邮件地址。但是今天,此功能仍然可以正常使用,但是我收到的JSON不再包含用户的电子邮件地址。
有人可以帮我吗?我想获取用户的电子邮件地址。谢谢 !

最佳答案

Azure对v2应用程序模型进行了重大更改,默认情况下您不再获得用户信息。

您可以在这里阅读所有相关信息:https://azure.microsoft.com/en-us/documentation/articles/active-directory-v2-preview-oidc-changes/,但总结一下:

  • openid范围用于为您提供用户的基本配置文件信息。
  • 与OpenID标准
  • 不符
  • Azure已更改为要求您请求profile范围才能访问该信息

  • 对于该示例,请找到以下位:
    # Scopes required by the app
    SCOPES = [ 'openid',
    'https://outlook.office.com/mail.read' ]

    并将其更改为:
    # Scopes required by the app
    SCOPES = [ 'openid',
    'profile',
    'https://outlook.office.com/mail.read' ]

    关于outlook - 无法使用Office 365 REST API登录电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35605103/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com