Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auth token not refreshing automatically #104

Open
sqr opened this issue Oct 23, 2022 · 1 comment
Open

Auth token not refreshing automatically #104

sqr opened this issue Oct 23, 2022 · 1 comment

Comments

@sqr
Copy link

sqr commented Oct 23, 2022

Hello, I am developing an integration for Dailymotion using react and have run into the following problem when using the JS SDK:

  • Auth is completed successfully, I can see the session information when running DM.getLoginStatus (session expires in 1h), but when the time threshold is crossed, and the site is reloaded, the session is lost and login is required again.

First I load the sdk using a hook:
const status = useScript('https://api.dmcdn.net/all.js')

I do DM.init once the script is loaded:

useEffect(() => {
    if (status === 'ready')  {
      window.DM.init({ apiKey: 'my_api_key', status: true, cookie: true });
      window.DM.getLoginStatus(function (response) {
        if (response.session != null) {
          console.log(response.session)
          dm_getUsername()
        } else {
          console.log('no session.')
        }
      })
    }
  }, [status])

My login button logic looks like this:

  const loginDM = (e) => {
    e.preventDefault()
    window.DM.login(
      function (response) {
        if (response.session) {
          // user successfully logged in
          console.log(response)
        } else {
          // user cancelled login
          console.log(response)
        }
      },
      {
        scope: "read write",
      }
    )
  }

The response I get from getLoginStatus has the following fields:

access_token: token
expires: 1666564079
expires_at: "1666564078"
scope: "read+write"
sig: sig
state: "dmauth_xxxxxxx"
token_type: "Bearer"
uid: my_user_id

This works perfectly fine for getting the session information, logging the username, but am I missing something needed to make the session refresh?

I have also noted that the cookie also expires in one hour. Shouldn't there be access to the cookie to perform the refresh? Is the cookie supposed to expire at the same time as the token?

Thank you very much for your time.

@sqr
Copy link
Author

sqr commented Oct 24, 2022

I have tried two approaches to fixing this:

  • Taking React out of the equation and just running plain JS + html, with the same results. Cookie expires in an hour and sesion breaks after that
  • Manually setting the cookie to expire later than the session. Problem persists (user is required to relogin after 1 hour)

Therefore I'm thinking that it is working as intended and I might be missing something required for the SDK to actually try the refresh? When the documentation says that the token will be refreshed "as long as the user interacts with the application" what does it mean? I am calling the API to log the username after DM.Init, which I guess counts as "interacting with the application".

However, exactly after the expiration of the session/cookie, it is destroyed and the user has to go through the authentication process of popup+user+password again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant