Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/funkhaus/wp-graphql-cors
Makes WP GraphQL's authetication "just work". It does this by customizing the CORS headers.
https://github.com/funkhaus/wp-graphql-cors
Last synced: 2 months ago
JSON representation
Makes WP GraphQL's authetication "just work". It does this by customizing the CORS headers.
- Host: GitHub
- URL: https://github.com/funkhaus/wp-graphql-cors
- Owner: funkhaus
- License: gpl-3.0
- Created: 2019-11-05T17:54:16.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-10-03T01:34:38.000Z (over 1 year ago)
- Last Synced: 2024-07-31T15:03:37.917Z (5 months ago)
- Language: PHP
- Homepage:
- Size: 86.9 KB
- Stars: 112
- Watchers: 8
- Forks: 21
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-wpgraphql - WPGraphQL CORS
- awesome-wordpress-gatsby - WPGraphQL Cors - This FREE plugin from @kidunot89 and @byfunkhaus claims to enable authentication with WPGraphQL to “just work” by allowing you to set CORS headers that GraphQL will accept, which means WordPress default auth cookies can be accepted. (Plugins / WordPress)
README
# WP GraphQL CORS
The primary purpose of this plugin is to make the [WP GraphQL](https://github.com/wp-graphql/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](https://github.com/wp-graphql/wp-graphql).
1. Upload this plugin to WordPress.
1. 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
}
}
```