0

I have used the Vue-Authenticate plugin for the social login and this is my configuration for the Github Login

 providers: {
    github: {
      clientId: 'my Id',
      redirectUri: 'https://' + process.env.PROJECT_DOMAIN,
      responseType: 'token',
      authorizationEndpoint: 'https://github.com/login/oauth/authorize',
    },
  },

And in the method through which is calling the method after authentication is

 authenticate(provider) {
      const this_ = this
      this.$auth.authenticate(provider).then(function () {
        const token = this_.$auth.getToken()
        if (provider === 'github') {
          const options = {
            headers: {
              Authorization: 'token ' + token,
            },
          }
          this_.$http
            .post('https://api.github.com/user', options)
            .then(function (response) {
              if (response.status === 200) {
                const { email, name, picture } = response.data
                const data = {
                  email,
                  name,
                  image: picture.data.url,
                }
                this_.createOAuth2User(data, provider)
              }
            })
            .catch((error) => {
              console.log(error)
            })
        }
      })
    },

I am able to receive an access token after successful authentication but when I try to use that token to access the user details and hit the https://api.github.com/user API I am getting 401 error. So is there something I am missing while authentication with github?

kissu
  • 40,416
  • 14
  • 65
  • 133
Mohit Chandani
  • 101
  • 1
  • 12
  • I never saw the `this.$auth.authenticate(provider)` format but rather the one in docs `this.$auth.loginWith('github')`. Also, why do you do the `if (provider === 'github')` test here? Are you sure this one is valid? Did you tried send it directly from your CLI with something like `curl -H "Authorization: token OAUTH-TOKEN" https://api.github.com`? – kissu Jun 11 '21 at 15:03
  • @kissu I am using Vue-authenticate not nuxt/auth – Mohit Chandani Jun 14 '21 at 06:22
  • Oh sorry, read it too quickly and usually people are using the other one. My bad! The curl point still stands out tho. – kissu Jun 14 '21 at 08:10
  • okay It seems like Github does not support Client-Side to get the data https://stackoverflow.com/questions/36907693/axios-cors-issue-with-github-oauth-not-getting-access-token I have to try with my server may be it will work – Mohit Chandani Jun 14 '21 at 09:56

0 Answers0