Skip to content

docs: Clarify Client SDK tutorial documentation #7171

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

Open
tr0b opened this issue Mar 21, 2025 · 1 comment
Open

docs: Clarify Client SDK tutorial documentation #7171

tr0b opened this issue Mar 21, 2025 · 1 comment
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@tr0b
Copy link

tr0b commented Mar 21, 2025

[disclaimer: I don't know if this is the right place to post this, or if I chose the right category]

I'm currently developing a simple Logto Client SDK for Clojure (re-frame SPA framework) and I've been mostly guiding myself with this Implement Client SDK documentation, based in Vanilla JS. So far I'm almost finished (The authentication seems to work; auth token, refresh token, id token are successfully stored on sign-up/sign-in with my current implementation, authorization is still wip) but the way certain details are written in this tutorial creates some confusion for me.

What problem did you meet?

Take for example, this section https://blog.logto.io/implement-client-sdk#handle-user-sign-in-callback

access_token: The default authorization code returned by the authorization server. Can be used to call the user info endpoint and retrieve authenticated user information.

and then the code for saving the token is shown, as below:

private async saveTokens({refreshToken, idToken, accessToken}) {
  this.storage.setItem('refreshToken', refreshToken);
  this.storage.setItem('idToken', idToken);

  // opaque access token without resource indicator specification
  this.accessTokenMap.setItem('', accessToken)

}

But then later in the authorization section (https://blog.logto.io/implement-client-sdk#get-access-token-for-protected-resource-authorization) when the tutorial mentions how to to integrate the getAuthToken function (along with the refresh token mechanism), the author writes the following code snippet:

async getAccessToken(resource?:string, scopes?: string[]) {
  if (!this.idToken) {
    throw new Error('User not authenticated');
  }

  const accessTokenInStorage = this.accessTokenMap.getItem(`${resource}:${scopes.join(_)}`); // WIth its current implementation per the tutorial, this will return a string e.g. "Qdefs6FMAetUltw3dC5H_LZ4JPgSrKYj3ZL5vx1Kfz9"

  if (accessTokenInStorage && accessTokenInStorage.expiresAt > Date.now() / 1000) { // There's no expires_at value here
      return accessToken.token;
  }

  return await this.getAccessTokenByRefreshToken(resource, scopes);
}

It isn't immediately obvious that, the developer needs to store both the token AND the expires_in (or expires_at, I'm also confused here) attribute in the opaqued/resources:scope access-token session value e.g. like this

{
"": {token: Qdefs6FMAetUltw3dC5H_LZ4JPgSrKYj3ZL5vx1Kfz9, expires_in: 3600}
}

Describe what you'd like Logto to have

Maybe the blog entry should be updated to explain a bit further how to properly store the access token in the session?

Copy link

github-actions bot commented Apr 5, 2025

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the stale label Apr 5, 2025
@gao-sun gao-sun added feature-request Something cool or not cool and removed stale labels Apr 16, 2025
@gao-sun gao-sun added documentation Improvements or additions to documentation and removed feature-request Something cool or not cool labels Apr 16, 2025
@gao-sun gao-sun changed the title feature request: Clarify Client SDK tutorial documentation docs: Clarify Client SDK tutorial documentation Apr 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Development

No branches or pull requests

3 participants