feathersjs-ecosystem / authentication-oauth2

[MOVED] OAuth 2 plugin for feathers-authentication
https://github.com/feathersjs/feathers
MIT License
26 stars 15 forks source link

Implement oauth2 with graphql #25

Closed LubomirIgonda1 closed 6 years ago

LubomirIgonda1 commented 7 years ago

I am using feathers server and I want to implement Oauth2 authentification with facebook or github strategy or whatever. But I also would like to use with graphql

But I dont know how to implement with graphql. It works with your example as a API if I send GET request on callback url it works correctly I get token but I'd like do this with graphql as for example in LOCAL or LDAP strategy


authentication.configure(hooks())
        .configure(rest(base).superagent(superagent))
        .configure(auth({ storage: localStorage }));

RootMutation: {
    signInLocal(root, {email, password}, context){
        return authentication.authenticate({
            strategy: 'local',
            email: email,
            password: password
        }, context).then(data=>{
            // console.log(data)
            return data
        })
    },
    signInLdap(root, {username, password}, context){
        return authentication.authenticate({
            strategy: 'ldap',
            username: username,
            password: password
        }, context).then(data=>{
            // console.log(data)
            return data
        })
    }
}

I tried

RootQuery: {        
    signInGithub(root, data, context){
        return authentication.authenticate({
            strategy: 'github',
        }, context).then(data=>{
            console.log(data)
            return data
        })
    }
}

But I got error

feathers-authentication:passport:authenticate 'github' authentication redirecting to https://github.com/login/oauth/authorize?response_type=code&redirect_uri=https%3A%2F%2Flocalhost%3A3000%2Fauth%2Fgithub
%2Fcallback&scope=user&client_id=0b786a43497059d2a28b 302 +3ms
feathers-authentication:middleware:failure-redirect Redirecting to https://github.com/login/oauth/authorize?response_type=code&redirect_uri=https%3A%2F%2Flocalhost%3A3000%2Fauth%2Fgithub%2Fcallback&scope=
user&client_id=0b786a43497059d2a28b after failed authentication. +7ms
Error: Unexpected end of JSON input

If i write this topic on bad place I am sorry for that Thak you for helping

daffl commented 6 years ago

oAuth needs to be triggered from the browser and then redirected. The new guide at https://docs.feathersjs.com/guides/auth/recipe.express-middleware.html should help using it in the GraphQL express middleware. Closing since besides that, GraphQL authentication is currently outside of the scope of Feathers authentication.