Создание проблемы Jira через приложение OAuth 2.0 (3LO) завершается ошибкой {"code":401, "message": "Unauthorized"}.

Я стажер-разработчик и интегрирую продукт с программным обеспечением Jira (облако). Я использую python и Django веб-фреймворки для разработки.

Я следовал документации https://developer.atlassian.com/cloud/jira/platform/oauth-2-3lo-apps/ и успешно получил токен доступа. Я выполнил следующие шаги:

  1. Created an OAuth 2.0 (3LO) app in the developer console. Configured permissions for ‘Jira platform REST API’ and ‘User identity API’. I selected the rotating refresh tokens option. Added the callback URL as ‘http://localhost:8000/callback’
  2. Direct user to authorization URL to get the authorization code. In the Authorization URL scope is defined as follows:
    scope = ['write:jira-work read:jira-user read:me read:jira-work']
  3. As the response receives the code and state variables.
  4. Exchanged the code value to the access token. The received response is as follows:

{"access_token": "значение токена отображается здесь", "scope": "write:jira-work read:jira-work read:jira-user read:me", "expires_in":3600, "token_type": "Bearer"}

  1. Successfully received the clould_id using the access token.

    header = {'Authorization': 'Bearer {}'.format(client.token['access_token']), 'Accept': 'application/json'}   
    response = requests.get('https://api.atlassian.com/oauth/token/accessible-resources', headers=header)
    
  2. Retrieved the public profile of the authenticated user successfully.

    response = requests.get('https://api.atlassian.com/me', headers=header)
    
  3. When I tried to create an issue, it ends up with the following error: {"code":401,"message":"Unauthorized"}. I’m referring to https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-post I am using email (logged-in user email) and API token to authorize. Is there any problem with my auth parameter? It would be great if you could help me to find out the reason for this error.

python код для создания выпуска:

     def post_issue(request): 
         if request.method == 'POST':
            project = request.POST['project']
            issue_type = request.POST['issue_type']
            summary = request.POST['summary']

            email = request.session['profile']['email']
            token = request.session['access_token']
  
            header1 = {'Accept':'application/json','Content-Type':'application/json'}
            data = { 'fields': 
                     {'project':{'name':project}, 
                      'summary': summary,
                      'issuetype':{'name': issue_type}
                     }
                   }

            response = requests.request('POST', url='https://api.atlassian.com/ex/jira/%s/rest/api/3/issue'%(request.session.get('cloud_id')), data = json.dumps(data), headers=header1 , auth=HTTPBasicAuth(email,token))
            if response.status_code == 201:
              print('Successfully created Issue')
            else:
              print('Could not create Issue')
              print('Response:', response.content)
Вернуться на верх