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

jwt_auth_iss filter not working #140

Open
radicek opened this issue Oct 1, 2021 · 1 comment
Open

jwt_auth_iss filter not working #140

radicek opened this issue Oct 1, 2021 · 1 comment

Comments

@radicek
Copy link

radicek commented Oct 1, 2021

From docs:

/**
 * Change the token issuer.
 *
 * @param string $iss The token issuer.
 * @return string The token issuer.
 */
add_filter(
    'jwt_auth_iss',
    function ( $iss ) {
        // Modify the "iss" here.
        return $iss;
    }
);

But when I try to set it, nothing happens, iss still defaults to site address 😕

add_filter( 'jwt_auth_iss', function () {
    // Default value is get_bloginfo( 'url' );
    return 'https://example.com';
});
@Parkerhiphop
Copy link

Parkerhiphop commented Nov 4, 2024

I found this:

/**
* Allow multiple domains to be used as token iss value
* This is useful if you want to make your token valid over several domains
* Default value is the current site url
* Used along with the 'graphql_jwt_auth_token_before_sign' filter
*/
$allowed_domains = array(get_bloginfo('url'));
$allowed_domains = apply_filters('graphql_jwt_auth_iss_allowed_domains', $allowed_domains);
/**
* The Token is decoded now validate the iss
*/
if ( ! isset( $token->iss ) || ! in_array( $token->iss, $allowed_domains ) ) {
// See https://github.com/wp-graphql/wp-graphql-jwt-authentication/issues/111
self::set_status(401);
return new \WP_Error( 'invalid-jwt', __( 'The iss do not match with this server', 'wp-graphql-jwt-authentication' ) );
}

If you want to fix the The iss do not match with this server, you can try

add_filter('graphql_jwt_auth_iss_allowed_domains', function($allowed_domains) {
    return array_merge($allowed_domains, [
       'https://example.com',
       'https://example-2.com'
    ]);
});

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

No branches or pull requests

2 participants