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

applying filter for graphql_require_authentication_allowed_fields this not working #167

Open
tareq0065 opened this issue Aug 6, 2022 · 0 comments

Comments

@tareq0065
Copy link

tareq0065 commented Aug 6, 2022

I have applied filter for this "graphql_require_authentication_allowed_fields". It's from the official documentation for allowing login field from the authentication. But it's not working.

`add_action( 'do_graphql_request', 'force_graphql_api_authentication', 10, 1 );

function force_graphql_api_authentication( $query ) {
if ( ! defined( 'GRAPHQL_HTTP_REQUEST' ) || true !== GRAPHQL_HTTP_REQUEST ) {
    return;
}

$introspection_query = \GraphQL\Type\Introspection::getIntrospectionQuery();
$is_introspection_query = trim($query) === trim($introspection_query);

if ( $is_introspection_query ) {
    return;
}

if ( ! get_current_user_id() ) {
    throw new \GraphQL\Error\UserError( __( 'You do not have permission to access the API', 'preachitgwl' ) );
}
}

add_filter(
'graphql_require_authentication_allowed_fields',
function( $allowed ) {
    $allowed[] = 'login';
    return $allowed;
}, 10, 1 );`
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

1 participant