1

我必须为我们的命令行应用程序(Django 应用程序)启用 OpenID 例如:每当用户尝试访问我们的 API 时,我必须确保使用 OpenID(Microsoft/Google)对用户进行身份验证。我正在尝试编写一个 Shell 脚本来访问 OpenID 网站,然后将 cookie 存储在用户的机器上,每当他尝试访问第二个应用程序时,他应该根据我存储在他机器上的 cookie 获得访问权限。

我正在尝试使用此处提到的方法,每当我尝试访问第二个 url 时,都会收到错误消息“您的浏览器当前设置为阻止 cookie。您需要允许 cookie 使用此服务。”

我的网站不在单个域上,它们使用 OpenID 进行身份验证。

  1. 我登录了第一个网站,该网站将我重定向到 OpenID 网站 (Azure AD)
  2. 我使用带有用户名和密码的 curl 成功访问了重定向的 url 并存储了 cookie。
  3. 当我尝试使用下面的行登录到第二个网站时,我看到了这个错误。(由于我存储了 cookie,它应该能够读取它们并打开第二个网站页面)

curl --cookie ./somefile https://secondwebsite.com/b

这是我的完整脚本

#Setting redirect url in IP variable
set IP=`curl -w "%{url_effective}\n" -I -L -s -S http://mysite1.com -o /dev/null`
echo "Trying to Authenticate.."
curl -L -s -S -I -k -v -i --user "username@microsoft.com" -D ./temp/cookie $IP
echo "Authentication successful"
#I need to check if the cookie is set or not, If it is set Authentication is successful

echo "Trying to access the second url"
#The below line is failing, When I wrote the whole content to html file, I see the error mentioned above (Your browser is currently set to block cookies. You need to allow cookies to use this service) 
curl --cookie ./temp/cookie https://secondwebsite.com/

总结一下,我遇到了两个问题

  1. 无需再次登录即可将用户身份验证到第二个站点
  2. 有时,身份验证 url 会要求用户输入密码,该密码将发送给移动用户(2 因素身份验证)。有关如何处理这种情况的任何指示?
4

1 回答 1

0

有适当的安全方法可以让您的命令行应用程序访问您的 API。

[OpenId Connect RFC] ( http://openid.net/specs/openid-connect-core-1_0.html ),允许您使用公共客户端 [代码流] ( http://openid.net/specs/openid -connect-core-1_0.html#CodeFlowAuth ) 以获取 access_token 和 refresh_token。用户第一次可以这样做,以后使用命令行应用程序可以使用刷新令牌不断更新新的访问令牌并调用 API。

Azure AD B2C 有一些示例展示了如何调用 [来自桌面应用程序的代码流] ( https://docs.microsoft.com/en-us/azure/active-directory-b2c/active-directory-b2c- devquickstarts-native-dotnet)和相应的GitHub

此链接有更多详细信息https://docs.microsoft.com/en-us/azure/active-directory-b2c/active-directory-b2c-reference-oauth-code#4-refresh-the-token

这样,您的命令行应用程序就不会收集敏感信息,例如密码或 mfa 详细信息。它调用浏览器让 AAD B2C 执行配置的最安全的身份验证,并为应用程序提供 access_token。从那时起,命令行只需将 access_token 用作不记名令牌,通常将其放在 Authorization 标头中。

于 2017-04-13T18:45:26.467 回答