773 Star 1.5K Fork 351

开源中国 / Gitee Feedback

 / 详情

使用 API 创建 Pull Request 失敗 出現 {"message":"401 Unauthorized"}

结束任务
Task
创建于  
2018-05-24 03:50

該問題是如何引起的?

使用 API 创建 Pull Request 失敗 出現 {"message":"401 Unauthorized"}

重現步驟

access_token 是利用 client-oauth2 直接透過帳密登入的方式取得

export function getToken(options: {

   username?: string,
   password?: string,

   access_token?: string,

   clientId: string,
   clientSecret: string,

   accessTokenUri?: string,
}): Promise<ClientOAuth2.Token>
{
   options.accessTokenUri = options.accessTokenUri || GITEE_ACCESS_TOKEN_URI;

   let giteeAuth = new ClientOAuth2({
      clientId: options.clientId,
      clientSecret: options.clientSecret,
      accessTokenUri: options.accessTokenUri,
   });

   if (options.access_token)
   {
      //return giteeAuth.jwt.getToken(options.access_token);

      return Promise.resolve(giteeAuth.createToken(options.access_token, {
         token_type: 'bearer',
      }));
   }

   return giteeAuth.owner.getToken(options.username, options.password);
}

發送 api 請求也是透過這個模組來發送

查詢資料之類的 api 都能正常使用

但是 建立 PR 的部分 卻一直出現 {"message":"401 Unauthorized"}

{ url: 'https://gitee.com/api/v5/repos/目標帳號/倉庫/pulls',
  method: 'POST',
  body:
   { title: 'title777',
     head: '來源帳號:master',
     base: 'master',
     body: 'body666' },
  query: {},
  headers: { Authorization: 'Bearer 取得的access_token' } }

目標是將來源分支 發送 PR 目標 repo 來進行合併


另外 如果是透過 https://gitee.com/api/v5/swagger#/postV5ReposOwnerRepoPulls

卻能正常發送 PR


應用的部分在建立時 權限有全部勾選

不過應用主頁 與 回傳地址 是 直接填寫 https://gitee.com 就是

但是因為是利用帳密的方式來取得 token 這點應該不影響才對

報錯信息

{"message":"401 Unauthorized"}

评论 (2)

bluelovers 创建了任务
bluelovers 更新了任务
Yashin 指派了任务给frech

把 access_token 放到body里试试

{ url: 'https://gitee.com/api/v5/repos/目標帳號/倉庫/pulls',
  method: 'POST',
  body:
   { title: 'title777',
     head: '來源帳號:master',
     base: 'master',
     body: 'body666',
     access_token: <Bearer 取得的access_token>},
  query: {},
}

已解決 原來取得 token 時 必須要指定 scope
而不能自動取得應用建立時設定的權限

bluelovers 关闭了任务
诺墨 任务状态已完成 修改为已验收
诺墨 将工作项从 任务 迁移到 Task
诺墨 任务类型任务 修改为Task
诺墨 任务状态已验收 修改为结束任务

登录 后才可以发表评论

状态
负责人
项目
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
预计工期 (小时)
参与者(2)
905323 frech 1578935509
Ruby
1
https://gitee.com/oschina/git-osc.git
git@gitee.com:oschina/git-osc.git
oschina
git-osc
Gitee Feedback

搜索帮助