Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

OAuth2 token 401Unauthorized

Hi, Everybody :).
I tried to connect to confluence cloud using OAuth2:
I send a post request to https://auth.atlassian.com/oauth/token and succeed to get the access_token :
This is a POST request body:
{
"grant_type": "authorization_code",
"client_id": "xxxxx",
"client_secret": "xxxxx",
"code":"xxxx",
"redirect_uri":"xxxx"
}
The problem when I used to send GET Request and I add the Bearer {token} for example https://MY_API.atlassian.net/wiki/rest/api/content/
using postman
The response is :
<!DOCTYPE html>
<html lang="en">

 

<head>
<meta charset="utf-8">
<meta name="description" content="Encountered a 401 - Unauthorized error while loading this page.">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Atlassian Cloud Notifications - Page access unauthorized</title>
<link rel="stylesheet" href="/_edge/resources/aui-prototyping.css">
<style>
body {
background: #fff;
}

 

main {
margin: auto;
padding-top: 120px;
text-align: center;
}

 

.suggestion {
font-size: 16px;
color: rgb(94, 108, 132);
width: 350px;
padding-top: 20px;
margin: auto;
}
</style>
</head>

 

<body>
<main>
<img
src="/_edge/resources/images/error-generic.svg"
alt="error icon"
width="120"
/>
<h2>
There was a problem accessing this content
</h2>
<p class="suggestion">
Encountered a 401 - Unauthorized error while loading this page.
</p>
</main>
</body>

 

</html>
I need your help :)
Thanks :).

1 answer

0 votes
Shannon S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Sep 16, 2021

Hi Adam,

Good afternoon, and welcome to Atlassian Community. It's nice to have you join us.

Can you help clarify what you're looking to do exactly? Are you developing an app for Atlassian Cloud? To use OAuth, you need to enable it for your app in your developer console. See OAuth 2.0 (3LO) apps and Security Overview. If you still have problems authenticating your application, reach out to your developer forum: Atlassian Developer Community.

If you're looking to access the Cloud API, then you can use the API token. See Basic auth for REST APIs. 

I hope this helps! Let me know if you have any trouble.

Take care,

Shannon

Thanks, Shannon for your reply and sorry for the delay.
I know how the basic auth works and it works for me good.
but I need to fetch the data using OAuth2.

First Question:


I get the token using Post Request to https://auth.atlassian.com/oauth/token

Body Request :

{
"audience": "api.atlassian.com",
"grant_type":"client_credentials",
"client_id": "xxxx",
"client_secret":"xxxx"
}
and I get the token from the response.
after that, I create HTTP Get for example to:
and I add the Authorization header Bearer + my token.

But The response  status is 401 and the body  
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8">
<meta name="description" content="Encountered a 401 - Unauthorized error while loading this page.">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Atlassian Cloud Notifications - Page access unauthorized</title>
<link rel="stylesheet" href="/_edge/resources/aui-prototyping.css">
<style>
body {
background: #fff;
}

main {
margin: auto;
padding-top: 120px;
text-align: center;
}

.suggestion {
font-size: 16px;
color: rgb(94, 108, 132);
width: 350px;
padding-top: 20px;
margin: auto;
}
</style>
</head>

<body>
<main>
<img
src="/_edge/resources/images/error-generic.svg"
alt="error icon"
width="120"
/>
<h2>
There was a problem accessing this content
</h2>
<p class="suggestion">
Encountered a 401 - Unauthorized error while loading this page.
</p>
</main>
</body>

</html>
 I am using the same account for my confluence and developer console.
Second Question:
The other question is why I get "expires_in": 3600?
how can I change it?
Shannon S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Sep 28, 2021

Hi Adam,

Thank you for your reply. Unfortunately, I'm not too familiar with this, but I'll share some threads that might help you:

Because the Atlassian Community is more geared towards end-users, it's better to raise this question on the Atlassian Developer Community instead. This is because they are more familiar with this feature and are better equipped to answer your question.

Best of luck, and take care!
Shannon

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events