Microsoft图形无法使用刷新令牌获取刷新令牌

时间:2019-06-12 10:28:27

标签: python django-rest-framework microsoft-graph

我第一次能够同时获得访问令牌和刷新令牌, 然后,当我使用刷新令牌进行刷新时,它只给了我返回访问令牌,也没有给我返回刷新令牌,我想同时获得刷新令牌和访问令牌,

request_url = "https://login.microsoftonline.com/common/oauth2/v2.0/token"

headers = {"Content-Type": "application/x-www-form-urlencoded"}

scope_list = ["https://graph.microsoft.com/Calendars.ReadWrite"]
scope = "%20".join(scope_list)

# redirect_uri = f"{settings.FRONTEND_BASE_URL}/microsoft/login"
redirect_uri = (
    f"https://someuri.com/login"
)

refresh_token = user.profile.calendar_settings.outlook_refresh_token

payload = {
    "client_id": "",
    "scope": scope,
    "redirect_uri": redirect_uri,
    "client_secret": "",
    "grant_type": "refresh_token",
    "refresh_token": refresh_token,
}

response = requests.post(url=request_url, headers=headers, data=payload)

2 个答案:

答案 0 :(得分:0)

我通过将范围更改为此而起作用

scope = "https://graph.microsoft.com/Calendars.ReadWrite offline_access"

答案 1 :(得分:0)

请确保您的调用在有效载荷中包含以下参数

<块引用>
try:
        WebDriverWait(driver, 180) # here i have my question
        verification = input('Waiting for SMS... you have 180 seconds: ').strip()
        if len(verification) != 4:
            verification = input('Must be 4 numbers: ').strip()
        driver.find_element_by_name('OtpCode').send_keys(verification)
        try:
            WebDriverWait(driver, 20).until(EC.element_to_be_clickable(
                    (By.XPATH, "//button[@id='confirm__button']"))).click() #This is because button to confirm for a bit of seconds is blocked
            #driver.find_element_by_css_selector("button[id='confirm__button']").click() # don't pay attention to this
            time.sleep(8)
            print('LOGGIN SUCCESFUL!.')

            self.get_categories(driver)

        except selenium.common.exceptions.ElementClickInterceptedException:
            print('Code expired!.')
            time.sleep(10)
            driver.close()
            self.login(url)

    except selenium.common.exceptions.TimeoutException:
        print('Timeout!!!.')
        driver.close()

        return None

详情请参考下方截图

Postman request to get new access token with refresh token