2017-04-09 78 views
0

我必須爲我們的命令行應用程序(Django應用程序)啓用OpenID For Ex:無論何時用戶嘗試訪問我們的API,我必須確保用戶使用OpenID進行身份驗證(Microsoft /谷歌)。我正在嘗試編寫一個Shell腳本來訪問OpenID網站,然後將Cookie存儲在用戶的計算機上,並且每當他嘗試訪問第二個應用程序時,都應該根據我存儲在他的計算機上的Cookie進行訪問。CURL驗證到網站

我試圖使用here提到的方法,每當我嘗試訪問第二個網址時,出現錯誤「您的瀏覽器當前設置爲阻止Cookie,您需要允許Cookie使用此服務。

我的網站不在一個域中,他們使用OpenID進行身份驗證。

  1. 我登錄到第一個網站,該網站重定向我到OpenID的網站 (Azure的AD)
  2. 我訪問使用curl用戶名和密碼 成功並存儲在cookie中的重定向的URL。
  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 "[email protected]" -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/ 

總之,我附有2個問題

  1. 將用戶認證爲第二個站點,不帶ne登錄
  2. 有時身份驗證網址要求用戶的密碼, 將發送給用戶移動(雙因素身份驗證)。任何關於如何處理這種情況的指針,如果它出現?

回答

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作爲承載令牌,通常將其放置在授權標頭中。

+0

按照規範,它需要瀏覽器交互,但我正在尋找完全基於命令行的身份驗證。客戶端必須能夠與資源所有者的用戶代理(通常是Web瀏覽器)交互(https://tools.ietf.org/html/rfc6749#section-4.1) –