graphql-passport | use passport.js with GraphQL server | Authentication library

 by   jkettmann TypeScript Version: 0.6.6 License: MIT

kandi X-RAY | graphql-passport Summary

kandi X-RAY | graphql-passport Summary

graphql-passport is a TypeScript library typically used in Security, Authentication, Nodejs applications. graphql-passport has no bugs, it has no vulnerabilities, it has a Permissive License and it has low support. You can download it from GitHub.

graphql-passport provides simple functionality to authenticate with Passport.js from mutation resolvers. Inside your resolvers you can get access to the following functions and attributes inside the context. authenticate and login are basically passport.authenticate and passport.login wrapped in a promise. user, logout, isAuthenticated and isUnauthenticated are just copies of the corresponding passport functions and attributes.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              graphql-passport has a low active ecosystem.
              It has 136 star(s) with 17 fork(s). There are 8 watchers for this library.
              OutlinedDot
              It had no major release in the last 12 months.
              There are 7 open issues and 20 have been closed. On average issues are closed in 117 days. There are 2 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of graphql-passport is 0.6.6

            kandi-Quality Quality

              graphql-passport has 0 bugs and 0 code smells.

            kandi-Security Security

              graphql-passport has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              graphql-passport code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              graphql-passport is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              graphql-passport releases are not available. You will need to build from source code and install.
              Installation instructions are not available. Examples and code snippets are available.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of graphql-passport
            Get all kandi verified functions for this library.

            graphql-passport Key Features

            No Key Features are available at this moment for graphql-passport.

            graphql-passport Examples and Code Snippets

            No Code Snippets are available at this moment for graphql-passport.

            Community Discussions

            QUESTION

            Passport Authenticator complains of that 'this' could be instantiated with an arbitrary type
            Asked 2021-Sep-06 at 08:42

            I'm trying to type a function to accept both local and general passport authenticator. Unfortunately I'm getting a "this" Typescript error:

            ...

            ANSWER

            Answered 2021-Sep-06 at 08:42

            There seems to be an issue with either the typings of Passport or some underlying issue with Authenticator. To be honest, I'm not sure what TS is complaining about, when I redefine the type exactly as it was before, just re-declaring use and unuse the error goes away. My only guess is that passport overlays the Authenticator interface somewhere or there is a typescript bug:

            Source https://stackoverflow.com/questions/68971291

            QUESTION

            Lighthouse GraphQL - How to return current_user in mutation resolver?
            Asked 2020-Nov-18 at 05:16

            I have a situation where I'm writing a custom mutation resolver, and currently have to pass the current_user's ID from my frontend to be able to then perform a ::find on the User model. What would be ideal however, is to be able to use an instance of current_user so that I don't have to rely on passing over an ID to my GraphQL server.

            I'm still fairly new to the world of Laravel and GraphQL in general, however I've been reading up on the Lighthouse docs that mention the @auth directive, and other StackOverflow answers that mention using auth('api')->user(), however that returns NULL for me. I should also mention that I'm using the lighthouse-graphql-passport-auth library for dealing with user authentication, if that makes any difference. Does anybody know how to access current_user?

            ...

            ANSWER

            Answered 2020-Nov-18 at 05:16

            I found an interesting part in the lighthouse-graphql-passport-auth docs that discuss setting a [global middleware][3] to insert the logged in user into the $context. This was exactly like what I needed, and after adding the line into the middleware section of lighthouse.php config as mentioned in the docs, I was able to use $context->user() to return the currently logged in user.

            Source https://stackoverflow.com/questions/64882371

            QUESTION

            How to setup authentication with graphql, and passport but still use Playground
            Asked 2020-Aug-21 at 07:01

            After adding authentication to our backend Graphql server the "Schema" and "Docs" are no longer visible in the Graphql Playground. Executing queries when adding a token to the "HTTP HEADERS" in the Playground does work correctly when authenticated and not when a user isn't authenticated, so that's ok.

            We disabled the built-in Playground from Apollo-server and used the middleware graphql-playground-middleware-express to be able to use a different URL and bypass authentication. We can now browse to the Playground and use it but we can't read the "Schema" or "Docs" there.

            Trying to enable introspection didn't fix this. Would it be better to call passport.authenticate() in the Context of apollo-server? There's also a tool called passport-graphql but it works with local strategy and might not solve the problem. I've also tried setting the token in the header before calling the Playground route, but that didn't work.

            We're a bit lost at this. Thank you for any insights you could give us.

            The relevant code:

            ...

            ANSWER

            Answered 2020-Aug-21 at 06:58

            I figured it out thanks to this SO answer. The key was not to use passport as middleware on Express but rather use it in the Graphql Context.

            In the example code below you can see the Promise getUser, which does the passport authentication, being used in the Context of ApolloServer. This way the Playground can still be reached and the "Schema" end "Docs" are still accessible when run in dev mode.

            This is also the preferred way according to the Apollo docs section "Putting user info on the context".

            Source https://stackoverflow.com/questions/63484171

            QUESTION

            How to forward user sessions in Next.js + Graphql decoupled architecture?
            Asked 2020-May-24 at 06:01

            I'm building a next.js project and while I usually would just use the "Custom Express Server" method to implement my graphql API (using apollo-server-express), I thought that it might be a good idea if I decoupled the next.js project from the graphql API so that each of the servers are hosted on different machines.

            But usually I would implement any session-related logic in the graphql API, using something like graphql-passport; I figured that's good practice because if I ever choose to add another frontend (maybe a mobile app or something) they can share the same session logic. But given that I'm server side rendering content with next.js, how do I forward the user's session info to the graphql server? Because the next.js server shouldn't have to redo authentication, right?

            Let me know if there are any flaws in the architecture too, I'm kind of new to this.

            ...

            ANSWER

            Answered 2020-May-24 at 06:01

            Using the Next server to run the GraphQL service is certainly not a good idea, so yes, do separate the two.

            Letting the Next server SSR-render pages with user specific content using the users session is probably not a good idea either, unless you have some specific use case that requires the served HTML pages to have the user specific data in them already. The reasons for this are:

            • SSR rendering will require lots of server side computations since all pages always will have to be rerendered.

            • NextJS is moving away (since v9.3) from the getInitialPros() way of doing things towards using getStaticProps() to generate a page that is common for all users and which can load its session dependent stuff straight from the GraphQL API once it is displayed on the client device.

            This approach will generally have higher performance and scale much better.

            Should you really want to go the "SSR with user session data" route you start in the getServerSideProps(context) method, where context.req is the actual request which will have all your session data in it (cookies or headers).

            This session data you can then extract from the req and pass on to the GraphQL server requests that require authentication.

            Source https://stackoverflow.com/questions/61979393

            QUESTION

            Error with authenticated user using guard and can to access to some model
            Asked 2020-May-01 at 13:54

            I'm using lighthouse-php to make a graphql api and I'm having a trouble changing middleware (it will be deprecated in new versions) directive to guard.

            ...

            ANSWER

            Answered 2020-May-01 at 13:54

            In the meantime I've found another solution mentioned in the documentation:

            https://lighthouse-php.com/master/security/authentication.html#global

            So in short, I needed to add the AttemptAuthentication middleware to the lighthouse config. I use this with @auth(guard: "api") added to all my types.

            Source https://stackoverflow.com/questions/60110716

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install graphql-passport

            You can download it from GitHub.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            Install
          • npm

            npm i graphql-passport

          • CLONE
          • HTTPS

            https://github.com/jkettmann/graphql-passport.git

          • CLI

            gh repo clone jkettmann/graphql-passport

          • sshUrl

            git@github.com:jkettmann/graphql-passport.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link