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

Define onTokenExpired event #25

Open
jfoliveira opened this issue Jun 2, 2020 · 8 comments · May be fixed by #907
Open

Define onTokenExpired event #25

jfoliveira opened this issue Jun 2, 2020 · 8 comments · May be fixed by #907
Labels
good first issue Good for newcomers type: enhancement New feature or request

Comments

@jfoliveira
Copy link
Contributor

jfoliveira commented Jun 2, 2020

Is your feature request related to a problem? Please describe.

Currently SDK users need to implement a token refresh process if they want to keep a user logged in. This works fine, but could be easier for SDK users when a token expired, as token expiration HTTP 401 may require some logic to be differentiated from regular HTTP 401 status code.

Describe the solution you'd like

Describe alternatives you've considered

Check for HTTP status code equals 401 and send a token refresh request.

Pseudo-code, yet to be tested:

    public onTokenExpired: () => void;

    public tokenExpired(): void {
        if (this.onTokenExpired) {
            this.onTokenExpired();
        }
    }

Additional context

The responsibility on making the decision of refreshing a token or not doesn't change. It'll still be up to the SDK consumer to decide what to do.
We just want to assume the logic that will check the HTTP 401 Unauthorized response to tell which ones are related to token expiration and notify the client app.

@jfoliveira jfoliveira added the type: enhancement New feature or request label Jun 2, 2020
@danielSbastos
Copy link

Hi, @jfoliveira!
I just wanted to make sure I understood correctly the issue. Currently, the SDK exports a refreshTokenUser function. For any API request, the conditional as to whether the 401 is for an expired token or an unauthorized request is still being done client-wise, right? Therefore, this implementation would differentiate the two 401s, and, for example, for a given response, maybe add in the axios response intercept an error?

@jfoliveira
Copy link
Contributor Author

jfoliveira commented Jul 19, 2023

Therefore, this implementation would differentiate the two 401s

Correct.

for example, for a given response, maybe add in the axios response intercept

That could be a starting point.
The most important criteria is that a client application consuming this SDK, when initializing an instance of Devopness API client should be able to provide a callback to be invoked once the tokenExpired event is dispatched.

Example, pseudo code from a user consuming Devopness SDK-JS and logging the event to the console:

import { DevopnessApiClient } from '@devopness/sdk-js'

// 1) consumer initialize DevopnessApiClient instance 
const devopnessApi = new DevopnessApiClient();

// 2) consumer defines its own event handler for the`onTokenExpired` event:
public doThisWhenDevopnessTriggerTokenExpiredEvent(): void {
  console.log('Devopness `tokenExpired` event has been triggered.');
}

// 3) consumer tells client instance to invoke a custom method when the event is triggered:
devopnessApi.onTokenExpired = doThisWhenDevopnessTriggerTokenExpiredEvent;

// any other code interacting with Devopness SDK:
const userTokens = await devopnessApi.users.loginUser(...)

Then, on the SDK itself, we could check if the consumer defined an event handler and - if so - we trigger the externally defined method:

    public onTokenExpired: () => void;

    public tokenExpired(): void {
        if (this.onTokenExpired) {
            this.onTokenExpired();
        }
    }

Let us know if you have further questions.

Copy link

👋 Hi there!
This issue has been automatically marked as stale because there wasn't any activity in the past
3 weeks.

  • Please check if it is still relevant in the latest version of Devopness
  • If so, please update the issue with new details
    If this issue remains without activity for another week (completing a month without activity), it'll be automatically closed.

@github-actions github-actions bot added the status: no issue activity Issues that have been stale for more than three weeks label Nov 28, 2023
@jfoliveira jfoliveira added good first issue Good for newcomers and removed status: no issue activity Issues that have been stale for more than three weeks labels Dec 7, 2023
Copy link

👋 Hi there!
This issue has been automatically marked as stale because there wasn't any activity in the past
3 weeks.

  • Please check if it is still relevant in the latest version of Devopness
  • If so, please update the issue with new details
    If this issue remains without activity for another week (completing a month without activity), it'll be automatically closed.

Copy link

👋 Hi there!
This issue has been automatically marked as stale because there wasn't any activity in the past
3 weeks.

  • Please check if it is still relevant in the latest version of Devopness
  • If so, please update the issue with new details
    If this issue remains without activity for another week (completing a month without activity), it'll be automatically closed.

@github-actions github-actions bot added the status: no issue activity Issues that have been stale for more than three weeks label Jan 20, 2024
Copy link

github-actions bot commented Feb 4, 2024

❌ This issue was closed because it has been open and inactive for a month.
If you feel this is still a high-priority issue, or are interested in contributing, please open a new issue or pull request linking to this one, for context.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Feb 4, 2024
@jfoliveira jfoliveira reopened this Mar 25, 2024
@github-actions github-actions bot removed the status: no issue activity Issues that have been stale for more than three weeks label Mar 26, 2024
Copy link

👋 Hi there!
This issue has been automatically marked as stale because there wasn't any activity in the past
3 weeks.

  • Please check if it is still relevant in the latest version of Devopness
  • If so, please update the issue with new details
    If this issue remains without activity for another week (completing a month without activity), it'll be automatically closed.

@github-actions github-actions bot added the status: no issue activity Issues that have been stale for more than three weeks label Apr 16, 2024
Copy link

github-actions bot commented May 1, 2024

❌ This issue was closed because it has been open and inactive for a month.
If you feel this is still a high-priority issue, or are interested in contributing, please open a new issue or pull request linking to this one, for context.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale May 1, 2024
@jfoliveira jfoliveira reopened this May 7, 2024
@jfoliveira jfoliveira removed the status: no issue activity Issues that have been stale for more than three weeks label May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers type: enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants