Giter Club home page Giter Club logo

wp-graphql-cors's Introduction

WP GraphQL CORS

The primary purpose of this plugin is to make the WP GraphQL plugin authentication "just work". It does this by allowing you set the CORS headers that GraphQL will accept, which means that WordPress's default authentication cookies will be accepted.

This means that if a user is logged into WordPress, they will be able to see things like draft and private pages/posts via GraphQL.

Features

  • Allows WP-GraphQL to accept default WordPress cookies
  • Works across multiple domains (so you can have multiple frontends connected to one backend)
  • Allows you to filter out specific cookies for added security (perhaps you don't want to use this for WordPress authentication but do want to access other cookies)
  • Allows you to customize the GraphQL endpoint
  • Extends WP GraphQL to have a logout and login mutation
  • Allows you to filter out which cookies are allowed

Installation

  1. Requires WP GraphQL.
  2. Upload this plugin to WordPress.
  3. Config your GraphQL client (probably Apollo) to include credentials in requests. Generally this is a setting under httpLinkOptions and look to set credentials = "include".

Now if the browser is currently logged into WordPress, WP GraphQL will allow access to authenticated data.

Documentation

If all you want to do is allow draft, private and page previews to be viewed from the frontend, setting Send site credentials. and Add Site Address to "Access-Control-Allow-Origin" header to true will do this.

You'll also need to config your GraphQL client (probably Apollo) to include credentials in requests. Generally this is a setting under httpLinkOptions and look to set credentials = "include".

Logout Mutation

If enabled in the settings, WP GraphQL will have a new mutation available to allow a user to logout. This is useful if you want to build a "logout" button on a sites frontend.

mutation {
    logout(input: {clientMutationId = "anything unique"}){
        clientMutationId
        status
    }
}

Login Mutation

If enabled in the settings, WP GraphQL will have a new mutation available to allow a user to login.

mutation {
	loginWithCookies(input: {clientMutationId: "", login: "", password: ""}) {
        clientMutationId
        status
    }
}

wp-graphql-cors's People

Contributors

drewbaker avatar kidunot89 avatar eavonius avatar jacobarriola avatar oskarmodig avatar jonshipman avatar tsvecak avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.