Skip to content

applying filter for graphql_require_authentication_allowed_fields this not working #167

@tareq0065

Description

@tareq0065

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 );`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions