Code Monkey home page Code Monkey logo

Comments (6)

MisterJimson avatar MisterJimson commented on June 19, 2024 1

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.

junelau avatar junelau commented on June 19, 2024

@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.

alexandru-calinoiu avatar alexandru-calinoiu commented on June 19, 2024

Got it, makes sens, thank you.

from graphiql-dotnet.

pain0486 avatar pain0486 commented on June 19, 2024

@alexandru-calinoiu

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.

josephwoodward avatar josephwoodward commented on June 19, 2024

@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.

pain0486 avatar pain0486 commented on June 19, 2024

@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)

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.