如何使用graphql

时间:2017-05-16 09:49:51

标签: node.js oauth-2.0 graphql feathersjs

我正在使用羽毛服务器,我想用facebook或github策略或其他任何方式实现Oauth2身份验证。但我也想使用graphql

但我不知道如何使用graphql实现我使用https://github.com/feathersjs/feathers-authentication-oauth2如果我在回调网址上发送GET请求它可以作为API使用它正常工作我得到令牌但是我喜欢做这与graphql一样,例如在LOCAL或LDAP策略中

const authentication = feathers()

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

我试过

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

但我收到了错误

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

感谢您的帮助

0 个答案:

没有答案