title: How do I refresh an access token from Azure AD using django-rest-framework-social-oauth2?
body: <p>The <a href="https://github.com/PhilipGarnero/django-rest-framework-social-oauth2" rel="nofollow noreferrer">documentation</a> gives an example of how to convert an Azure access_token that the user already has from the login process, but I'm not seeing anything about how to refresh that token. I managed to roll my own using <a href="https://github.com/AzureAD/azure-activedirectory-library-for-python" rel="nofollow noreferrer">adal</a>, the Azure AD library for python, but I'm wondering if there's a better way using the tools included in DRF social oauth 2 or other django oauth packages that I'm just not finding. Please advise. Below is the function that refreshes my Azure AD token. </p>
  
  <pre><code>def refresh_social_access_token(self, request):
      """
      This function leverages adal 
      https://github.com/AzureAD/azure-activedirectory-library-for-python
      to refresh an expired access token.
  
      .acquire_token_with_refresh_token(self, refresh_token, azure_ad_app_key, 
                                        resource, azure_ad_app_secret)
      """
      user_social_auth = request.user.social_auth.filter(user=request.user) \
          .values('provider', 'extra_data')[0]
      context = AuthenticationContext(f'https://login.microsoftonline.com/{self.TENANT_ID}')
      token = context.acquire_token_with_refresh_token(
          user_social_auth['extra_data']['refresh_token'],
          SOCIAL_AUTH_AZUREAD_OAUTH2_KEY,
          user_social_auth['extra_data']['resource'],
          client_secret=SOCIAL_AUTH_AZUREAD_OAUTH2_SECRET
      )
      try:
          expiry = convert_iso_to_epoch(token["expiresOn"])
          user_social_auth = request.user.social_auth.get(user=request.user)
          user_social_auth.extra_data['expires_on'] = expiry
          user_social_auth.save()
  
      except KeyError:
          HttpError('Oauth2 token could not be refreshed as configured.')
  </code></pre>