Outlook 加载项 SSO 访问令牌丢失电子邮件声明
Outlook Add-In SSO access token missing email claim
我正在创建 outlook 加载项并尝试使用 SSO 访问令牌作为我的后端的授权。
我的流程正常。我触发我的加载项,获取访问令牌并使用访问令牌“登录”到我的后端。
但是,我遇到的问题是,尽管 a) 将其添加到 Azure 应用程序注册中的 API 权限,b) 添加到 WebApplicationInfo,但我没有在令牌中收到电子邮件声明。我应该收到吗?
Azure 应用程序注册权限
Web 应用程序信息
<WebApplicationInfo>
<Id>xxx</Id>
<Resource>api://localhost:3000/xxx</Resource>
<Scopes>
<Scope>openid</Scope>
<Scope>User.Read</Scope>
<Scope>profile</Scope>
<Scope>email</Scope>
</Scopes>
</WebApplicationInfo>
接收令牌的代码
OfficeRuntime.auth.getAccessToken( { allowSignInPrompt: true })
收到令牌
{
"aud": "api://localhost:3000/xxx",
"iss": "https://sts.windows.net/my_tenant_id/",
"iat": 1605992211,
"nbf": 1605992211,
"exp": 1605999711,
"acr": "1",
"aio": "E2RgYDDdzii4P/xP/cPTbg4lPk7dJ6c8aQnapLU19aiV+Zy400sA",
"amr": [
"pwd"
],
"appid": "xxx",
"appidacr": "0",
"family_name": "Adams",
"given_name": "Iain",
"ipaddr": "51.111.111.111",
"name": "Iain Adams",
"oid": "my_oid",
"pwd_exp": "157262",
"pwd_url": "https://portal.microsoftonline.com/ChangePassword.aspx",
"rh": "0.AAAAmj9NLsNP80SAITLYeWEJg9YOWdOzUgJBrv-q0ikqsBxHANs.",
"scp": "access_as_user",
"sub": "my_sub",
"tid": "my_tenant",
"unique_name": "iain@abc.com",
"upn": "iain@abc.com",
"uti": "1KNbNttkDUCrKXblaK5BAA",
"ver": "1.0"
}
虽然我知道在 upn 和 unique_name 声明中返回了电子邮件地址,并且,我知道 oid 应该用作该用户的唯一标识符,但是,我需要查找基于电子邮件地址(如果存在)。
您需要自定义访问令牌配置,然后将 email 添加为可选声明。转到 azure 门户>应用程序注册>你的应用程序>令牌配置。
解析令牌:
您需要注意:对于托管用户(租户内的用户),必须通过此可选声明或仅在 v2.0 上使用 OpenID 范围请求。
参见:Document。
“电子邮件”值是 optional claims. It's included by default if the user is a guest in the tenant. For managed users (it means, the users inside the tenant), it must be requested through this optional claim or, on v2.0 only, with the OpenID scope. For managed users, the email address must be set in the Office admin portal (https://portal.office.com/adminportal/home#/users) 的一部分。
我正在创建 outlook 加载项并尝试使用 SSO 访问令牌作为我的后端的授权。
我的流程正常。我触发我的加载项,获取访问令牌并使用访问令牌“登录”到我的后端。
但是,我遇到的问题是,尽管 a) 将其添加到 Azure 应用程序注册中的 API 权限,b) 添加到 WebApplicationInfo,但我没有在令牌中收到电子邮件声明。我应该收到吗?
Azure 应用程序注册权限
Web 应用程序信息
<WebApplicationInfo>
<Id>xxx</Id>
<Resource>api://localhost:3000/xxx</Resource>
<Scopes>
<Scope>openid</Scope>
<Scope>User.Read</Scope>
<Scope>profile</Scope>
<Scope>email</Scope>
</Scopes>
</WebApplicationInfo>
接收令牌的代码
OfficeRuntime.auth.getAccessToken( { allowSignInPrompt: true })
收到令牌
{
"aud": "api://localhost:3000/xxx",
"iss": "https://sts.windows.net/my_tenant_id/",
"iat": 1605992211,
"nbf": 1605992211,
"exp": 1605999711,
"acr": "1",
"aio": "E2RgYDDdzii4P/xP/cPTbg4lPk7dJ6c8aQnapLU19aiV+Zy400sA",
"amr": [
"pwd"
],
"appid": "xxx",
"appidacr": "0",
"family_name": "Adams",
"given_name": "Iain",
"ipaddr": "51.111.111.111",
"name": "Iain Adams",
"oid": "my_oid",
"pwd_exp": "157262",
"pwd_url": "https://portal.microsoftonline.com/ChangePassword.aspx",
"rh": "0.AAAAmj9NLsNP80SAITLYeWEJg9YOWdOzUgJBrv-q0ikqsBxHANs.",
"scp": "access_as_user",
"sub": "my_sub",
"tid": "my_tenant",
"unique_name": "iain@abc.com",
"upn": "iain@abc.com",
"uti": "1KNbNttkDUCrKXblaK5BAA",
"ver": "1.0"
}
虽然我知道在 upn 和 unique_name 声明中返回了电子邮件地址,并且,我知道 oid 应该用作该用户的唯一标识符,但是,我需要查找基于电子邮件地址(如果存在)。
您需要自定义访问令牌配置,然后将 email 添加为可选声明。转到 azure 门户>应用程序注册>你的应用程序>令牌配置。
解析令牌:
您需要注意:对于托管用户(租户内的用户),必须通过此可选声明或仅在 v2.0 上使用 OpenID 范围请求。
参见:Document。
“电子邮件”值是 optional claims. It's included by default if the user is a guest in the tenant. For managed users (it means, the users inside the tenant), it must be requested through this optional claim or, on v2.0 only, with the OpenID scope. For managed users, the email address must be set in the Office admin portal (https://portal.office.com/adminportal/home#/users) 的一部分。