我必须为我们的命令行应用程序(Django 应用程序)启用 OpenID 例如:每当用户尝试访问我们的 API 时,我必须确保使用 OpenID(Microsoft/Google)对用户进行身份验证。我正在尝试编写一个 Shell 脚本来访问 OpenID 网站,然后将 cookie 存储在用户的机器上,每当他尝试访问第二个应用程序时,他应该根据我存储在他机器上的 cookie 获得访问权限。
我正在尝试使用此处提到的方法,每当我尝试访问第二个 url 时,都会收到错误消息“您的浏览器当前设置为阻止 cookie。您需要允许 cookie 使用此服务。”
我的网站不在单个域上,它们使用 OpenID 进行身份验证。
- 我登录了第一个网站,该网站将我重定向到 OpenID 网站 (Azure AD)
- 我使用带有用户名和密码的 curl 成功访问了重定向的 url 并存储了 cookie。
- 当我尝试使用下面的行登录到第二个网站时,我看到了这个错误。(由于我存储了 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/
总结一下,我遇到了两个问题
- 无需再次登录即可将用户身份验证到第二个站点
- 有时,身份验证 url 会要求用户输入密码,该密码将发送给移动用户(2 因素身份验证)。有关如何处理这种情况的任何指示?