今天在使用Microsoft Graph 的時候,發現按照官方文檔,無論如何都不能獲取refresh_token,其他都沒問題,經過查詢,發現是因為在第一步,獲取code授權時,沒有給離線權限(offline_access)。
加上就可以了。
代碼片段:
{ client_id: 'xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx', response_type: 'code', redirect_uri: 'http://localhost:3000/callback', response_mode: 'query', scope: 'user.read offline_access', };
注意標紅位置。
參考資料:https://stackoverflow.com/questions/42533257/receiving-access-token-but-not-the-refresh-token-from-microsoft-graph-api
有空詳細總結一下 Microsoft Graph api的使用。