2016-10-21 125 views
2

有沒有人可以幫助我得到一個解決方案來驗證後端服務器?我使用Google帳戶登錄我的平臺,併發布id_token(使用ajax)。如何使用後端服務器進行身份驗證?

var msg = $.ajax({type: "POST", url: "controller/action", data: token, async: false}).responseText; 
if (msg=="ok"){ 
    window.location = "controller/action"; 
} 
else { 
    window.location = "controller/action"; 
} 

現在,我想驗證令牌以便將用戶信息(名稱,圖像,電子郵件)保存在數據庫中。
我看到這個https://developers.google.com/identity/sign-in/web/backend-auth。有沒有辦法使用它?

+0

你後端是在java? –

+0

它是一個grails控制器 –

+0

檢查這個鏈接它是一個很好的示例項目https://github.com/bagage/grails-google-authentification-example –

回答

1

發送GET請求任何RESTClient實現,並與您的令牌替換XYZ: -

https://www.googleapis.com/oauth2/v3/tokeninfo?id_token=xyz 

一旦你在RESTClient實現響應,那麼簡單地裝配在您方便的語言這個GET請求。在grails中獲取請求see this

希望它可以幫助你

+0

https://www.googleapis.com/oauth2/v3/tokeninfo?id_token = xyz是json,所以我可以把我想要的信息。但是,你能解釋我,我將如何發佈這個以及如何在服務器上處理它?有沒有示例代碼? –

相關問題