AxaFrance / oidc-client

Light, Secure, Pure Javascript OIDC (Open ID Connect) Client. We provide also a REACT wrapper (compatible NextJS, etc.).
MIT License
597 stars 160 forks source link

Redirect path in logout #713

Closed tiphaineruy closed 2 years ago

tiphaineruy commented 2 years ago

Issue and Steps to Reproduce

logout doesn't expose a callback uri option:

export declare const useOidc: (configurationName?: string) => {
    login: (callbackPath?: any) => any;
    logout: () => any;
    isLogged: boolean;
};
export declare const useOidcAccessToken: (configurationName?: string) => any;
export declare const useOidcIdToken: (configurationName?: string) => any;
//# sourceMappingURL=ReactOidc.d.ts.map

Versions

4.2.3

Screenshots

Expected

    login: (callbackPath?: any) => any;
    logout: (callbackPath?: string) => any;

Is there something else than appending the callbackPath to the logout endpoint that i'm missing ?


in oidc.ts line 434

    async logoutAsync() { <--- HERE
        const oidcServerConfiguration = await this.initAsync(this.configuration.authority);
        // TODO implement real logout
        await this.destroyAsync();  
        window.location.href = oidcServerConfiguration.endSessionEndpoint; <-- Add redirect
    }

Actual

Additional Details

I can open a PR for that If you want.

guillaume-chervet commented 2 years ago

Yes, there is a pr on appauth js about logout. I was waiting for a merge from it. I will investigate next monday on it. If you have time, a pr would be very cool.

Thank you very much for your feeback.

guillaume-chervet commented 2 years ago

This Pull Request merge would be nice => https://github.com/openid/AppAuth-JS/pull/198

bonnetb commented 2 years ago

Hi, I forked react-oidc and fitted it to a "merged" AppAuth (https://github.com/arssly/AppAuth-JS). Logout seems to work fine with react-oidc sample app.

bonnetb commented 2 years ago

Here is my feature branch : https://github.com/bonnetb/react-oidc/tree/feat/logout (not to be merged before https://github.com/openid/AppAuth-JS/pull/198 is merged)

guillaume-chervet commented 2 years ago

Awesome @bonnetb thank you,

May you set a message on https://github.com/openid/AppAuth-JS/pull/198, it would be cool a merge from them :)

ddecrulle commented 2 years ago

Do you have any news about this ?

I'm really concerned with and the lib AppAuth-JS sems to be off ...

guillaume-chervet commented 2 years ago

Me too, may be we will need to implement it here.

tielushko commented 2 years ago

Seems like AppAuth-JS hasn't been updated in a year. I wonder if it has become dead?

guillaume-chervet commented 2 years ago

Yearh, I will try to email the team. I am thinking to take the owership of it and ask openid team to certify their own library.

For example: axa-fr/appauthjs

guillaume-chervet commented 2 years ago

I'am waiting for any news from them => https://github.com/openid/AppAuth-JS/issues/209

If no news, I will fork it and ask openid team to certify the fork :/

tiphaineruy commented 2 years ago

I mean. For now its a 3 lines quick workaround:

oidc/vanilla/oidc.ts

    async logoutAsync(callbackPath: string | undefined = undefined) {
        const oidcServerConfiguration = await this.initAsync(this.configuration.authority);
        // TODO implement real logout
        ---> const url = callbackPath || location.pathname + (location.search || '') + (location.hash || '');
        await this.destroyAsync();
        if (oidcServerConfiguration.endSessionEndpoint) {
            window.location.href = ---> oidcServerConfiguration.endSessionEndpoint! + "?redirect_uri=" + encodeURI(url);
        }
        else {
            window.location.reload();
        }
    }

and

oidc/ReactOidc.tsx

export const useOidc = (configurationName = defaultConfigurationName) => {
    const getOidc = Oidc.get;

    const login = (callbackPath: string | undefined = undefined, extras: StringMap = null) => {
        return getOidc(configurationName).loginAsync(callbackPath, extras);
    };
    ---> const logout = (callbackPath: string | undefined = undefined) => {
        return getOidc(configurationName).logoutAsync(callbackPath);
    };

    let isAuthenticated: boolean = false;
    const oidc = getOidc(configurationName);
    if (oidc) {
        isAuthenticated = getOidc(configurationName).tokens != null;
    }

    return { login, logout, isAuthenticated };
}

An then set the call back path when you "logout" in your app.

guillaume-chervet commented 2 years ago

I made https://github.com/AxaGuilDEv/react-oidc/pull/761 But It does not seem to work with the identityServer demo.

tedoham commented 2 years ago

Is there any solution for the Identity Server? To redirect on logout?

guillaume-chervet commented 2 years ago

I will investigate

guillaume-chervet commented 2 years ago

It is done by #775 . I close thie issue tahnk you again for it. Feel free to reopen it if needed.