0

我正在開發mobile app使用azure-mobile-apps科羅拉多客戶端。我跟着這個https://cgillum.tech/2016/08/10/app-service-auth-and-azure-ad-b2c-part-2/獲得刷新令牌。使用azure-mobile-apps科爾多瓦客戶端刷新令牌和註銷

我在標頭中發送id_token。

var token = window.localStorage.getItem("token"); 
var appUrl = https://Mobile****.azurewebsites.net; 
var url = appUrl + "/.auth/refresh"; 
$http.get(url, { 
    headers: { 
     'X-ZUMO-AUTH': token 
    } 
}) 
.then(function(response) { 
    console.log(response); 
}); 

響應:401未經授權。 IDX10500:簽名驗證失敗。 無法解析SecurityKeyIdentifier ...

我比較了資源管理器和Tenant - > Application - > Keys中的密鑰。

兩者都是相同的。 我也想問一下關於註銷的問題,我們可以在這個端點/.auth/logout上發送同樣的內容。

+0

嗨@devangi,任何更新? –

+0

嗨,對不起,請延遲。是的,我想問一下這些令牌(mobileServiceAuthenticationToken,id_token&refresh_token)?過期時間,id_token&refresh_token可通過/.auth/me端點獲得。 我的觀察是,即使您在1小時內分享任何沒有使用mobileServiceAuthenticationToken(使用/.auth/refresh),但過期時間將會相同(在/.auth/me)。 如果您使用舊令牌調用/.auth/refresh,一小時後,它會給內部服務器提供500個錯誤。那麼什麼是mobileServiceAuthentication令牌的生命週期,id_token&refresh_token? – devangi

+0

關於如何保持用戶永久登錄,您可以參考[此線程](http://stackoverflow.com/questions/41310757/mobileservices-web-js-unauthorized-api-call)。 –

回答

1

爲了讓/.auth/refresh正常工作,就像之前提到的@mattchenderson一樣,請確保client.currentUser.mobileServiceAuthenticationToken已通過X-ZUMO-AUTH標題。

要註銷,您可以使用build-in SDK的註銷功能。 請嘗試使用以下代碼將用戶註銷到移動應用程序中。

client.logout().then(function() { 
    window.cookies.clear(function() { 
     $state.go('index'); 
    });   
}); 

注: Web視圖已存儲在Cookie中的登錄信息,並通過你的身份驗證提供者下次登錄時,瀏覽器會自動讀取cookie和完成登錄流程。所以請確保在註銷時cookie被清除。我用Phonegap-Cookies-Plugin來完成這項工作。請注意,它適用於PhoneGap和Cordova。

+0

感謝您的迴應,它已經解決了註銷和刷新令牌。 – devangi

1

X-ZUMO-AUTH標頭中提交的令牌應始終爲App Service令牌,而不是AAD ID令牌。使用Mobile Apps SDK的client.login()方法之一獲得此令牌。您可以從客戶端對象訪問此令牌(通過client.currentUser.mobileServiceAuthenticationToken)。

+0

謝謝你的迴應,是的,它解決了。 – devangi

相關問題