2016-09-23 89 views
1

我目前正在建立一個使用https://github.com/aspnet-contrib/AspNet.Security.OpenIdConnect.Server和asp.net核心身份作爲後備存儲的openid連接服務器。我知道協議,流程和安全漏洞。openidconnect.server,第三方提供商和重定向

當前設置如下: [server] - 授權服務器&資源服務器 [front-end] - 一個angularJS應用 [third-party-provider] - 谷歌 [external-app] - 其中要使用從[服務器]

的令牌的第二應用[front-end][external-app]都已註冊爲[server]的客戶端。所以,他們被允許檢索令牌。登錄頁面內置於[front-end]

請記住,登錄頁面等由[front-end]應用程序(而不是返回從一個的AccountController AuthView)

所示想象我願意與[external-app]登錄到從[server]得到一個身份。登錄頁面顯示爲[front-end]。然後,該流程將是以下幾點:

1. [external-app] -> http://[server]/account/authorize?client_id=[external-  
    app-clientid]&response_type=token&redirect_uri=http://[external-app- 
    redirecturi] 
2. [front-end] -> matches route -> show login page 
3. [front-end] -> user clicks on login with google 
4. [front-end] -> redirect to 'http://[server]/account/authorize/connect? 
    provider=Google&redirect_uri=http://[front- 
    end]/account/thirdparty/authorized&response_type=code&client_id=[front- 
    end-clientid] 
5. [server] -> no identity found, save request in session and let the user 
    login at the [third-party] (using ChallengeResult and also passing in the 
    request id which was stored in session) 
6. [third-party-provider] user logs in 
7. [front-end] -> http://[front-end]/account/thirdparty/authorized recieved 
    the code 
8. [front-end] -> exchange authcode for token with [server] using 
    http://[server]/account/token&grant_type=authorization_code&code= 
    [code]&redirect_uri=http://[front- 
    end]/account/thirdparty/authorized&client=[front-end-clientid] 
9. [server] -> generate claims and return token 
10. [front-end] -> token recieved 

一件事我很想念(這可能是一個程序錯誤,以爲瑕疵或其他)是我需要重定向回[external-app]與給定令牌。我是否需要在[front-end]上做到這一點?它的感覺和我有點確定我混合/匹配的東西錯了。誰能幫我嗎?

在此先感謝!

PS是的,我知道,應該是https。以上僅爲舉例目的;)

+0

您確定要構建自己的openid連接服務器嗎?您可能有充分的理由這麼做,但我想我會提及已經實施的解決方案,它完全符合您要實現的目標。看看Identity Server:https://github.com/IdentityServer/IdentityServer4 – henningst

+0

我目前使用https://github.com/aspnet-contrib/AspNet.Security.OpenIdConnect.Server,所以我沒有做這一切都在我自己的...但我需要有一些幫助重定向流:)我會更新我的問題,以反映即時通訊使用這個庫的事實! –

回答

0

對於類似於隱式流的交互式流,需要記住的重要一點是您必須將用戶重定向到身份提供者的授權端點,以便有機會準備授權響應。

您可以自由決定您的身份提供程序在收到授權請求和授權響應返回之間會發生什麼,但您無法將用戶從「前端」應用程序直接重定向到「外部應用程序」,因爲它無法生成授權響應(這不是它的作用)。

考慮重新設計流程,以便您的前端應用程序將您的用戶重定向到授權服務器,該授權服務器將自行將其重定向到您的外部應用程序。

+0

我們談話後,我完全按照您的建議做了,重做流程。它現在工作完美無缺:) 我對這個事實感到困惑,因爲'[front-end]'有兩個工作,例如,登錄'[前端]'本身,但也作爲'[external-app]'的授權端點。將它們看作兩個獨立的過程使一切變得清晰。 再次感謝您的幫助! –