Comments (6)
I don't quite understand the second case, where do we modify the fetch code to include the auth header? In the client side code? We would need to maintain a fork to do this?
A small bit of UI that lets you set custom headers in the UI would be perfect and flexible for other cases as well.
from graphiql-dotnet.
@alexandru-calinoiu If you are using cookie authentication, this line[https://github.com/JosephWoodward/graphiql-dotnet/blob/d5bc728c2318e740f50c756692bd332aeeee0ccf/src/graphiql/assets/index.html#L119] will do it for you.
However, if you are using tokens, you'll need to save your token as a cookie - and include it as a header in your request.
function getCookie(name) {
var re = new RegExp(name + "=([^;]+)");
var value = re.exec(document.cookie);
return value != null ? unescape(value[1]) : null;
}
and add the token to your request header
return fetch('/graphql', {
method: 'post',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': "Bearer " + getCookie("access_token")
}
}
from graphiql-dotnet.
Got it, makes sens, thank you.
from graphiql-dotnet.
function getCookie(name) { var re = new RegExp(name + "=([^;]+)"); var value = re.exec(document.cookie); return value != null ? unescape(value[1]) : null; }and add the token to your request header
return fetch('/graphql', { method: 'post', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', 'Authorization': "Bearer " + getCookie("access_token") } }
Where would you add this? Speaking about the Or is this something we would have to fork?
from graphiql-dotnet.
@pain0486 You'd have to make the modification to the index.html
file that's bundled with this library.
This definitely seems like something that would be good to build into this library so people don't have to modify the index file manually.
from graphiql-dotnet.
@josephwoodward Thanks... for the time being, I found an easy work around. I installed a Chrome extension called ModHeader
Then I added the authorization header and my token and everything started working fine.
from graphiql-dotnet.
Related Issues (20)
- Cannot get Mutation work HOT 1
- Separate routs for GraphQL and GraphiQL HOT 3
- Docs sidebar not working HOT 4
- Cannot find schema HOT 4
- OAuth integration? HOT 2
- graphql/ not loading, js error. Can't get schema. HOT 2
- Don't require path in UseGraphiQl to be absolute HOT 4
- Missing schema intellisense HOT 4
- Need to import GraphiQl namespace since GraphiQL 1.2.0 HOT 1
- Undefined Type on autocompletion
- Investigate how we could handle authentication of the graphiql endpoint HOT 4
- Drop Down Menu Selection Not Executing Correct Operation HOT 2
- How to use with .net 4.7 HOT 2
- Autosuggestion and document explorer not working with .Net core 3.1.1 HOT 3
- Get tests running in GitHub actions HOT 2
- Support graphiql-explorer plugin HOT 1
- Custom js support HOT 3
- Console error within graphiql-ui (404 POST ERROR)
- to delete HOT 1
- Error 500 while fetching document after version Upgrade of both graphiql and graphql.net
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphiql-dotnet.