如何通过 Auth0 获取 repo 的 github 访问令牌或其他权限?

问题描述 投票:0回答:1

我已经使用 Vue 构建了 SPA,并使用 Auth0 进行身份验证。我刚刚启用了 github 登录连接,它正在按预期工作,因为我已将其设置为有权访问用户的存储库,因此在注册过程中会要求该权限。但是,现在我不知道如何获取 github 访问令牌来实际获取存储库列表或执行其他任何操作。该文档有点稀疏,因此需要一些帮助。 我使用带有快速 API 后端的“@auth0/auth0-vue”库。我按照 auth0 的教程/模板进行操作,登录和注册工作正常。我现在如何获取 github 访问令牌来获得访问权限?之后我知道我只需调用“https://api.github.com/users/{username”/repos”端点来获取存储库详细信息,但如果我使用 auth0 访问令牌,它会返回未经授权的信息。

vue.js jwt github-api auth0
1个回答
0
投票

我看起来我有我称之为 enedpoints https://github.com/login/oauth/access_token/

这是一个 axios 调用,您可以使用它来获取令牌,我目前也收到一个 cors 错误。在此之后我不打算在我的客户端中使用它,所以这很可能不会成为问题:

export const getGithubRepos = async (path, accessToken, email) => {
  const params = new URLSearchParams();
  params.append('client_id', 'github_client_id');
  params.append('client_secret', 'github_secret');
  params.append('code', 'code_form_callback_url');

  axios.post('https://github.com/login/oauth/access_token/', params, {
    headers: {
      Accept: 'application/json',
    }
  })
  .then(response => {
    console.log('Access Token:', response.data.access_token);
  })
  .catch(error => {
    console.error('Error during token exchange:', error);
  });
};
© www.soinside.com 2019 - 2024. All rights reserved.