Authorization in Confluence REST API

  1. Currently, a user is logged in to Confluence;
  2. There is an external web application that saves attachments to a specific page.
  3. In order to make REST calls from the external app, I need the user's credentials for Confluence (which I do not have because authorization has already been passed), or it may be possible to use a session ID.

How can I obtain an access token for REST access? How can I make an ajax call using the Confluence access token?

$.ajax({
  url: "http://localhost:1990/confluence/rest/api/content",
  headers: "Basic=" + GET_SOMEHOW_ACCESS_TOKEN,
  success: function(html){
      console.log(html)
  }
 });

Answer №1

Attempting to mimic a user and carry out an action on their behalf without proper authentication is typically not allowed. This type of activity is considered a form of Cross-Site Request Forgery (CSRF), even if done with good intentions. It is important for applications to have safeguards in place to prevent such unauthorized actions.

Answer №2

After some investigation, it seems that it is indeed possible to impersonate a user using the API. I came across a helpful response from Martin Cassidy on the Atlassian forum, which I have slightly edited for spelling:

To impersonate a user, you need to follow these steps:

  • Create a public-private key pair
  • Configure the trusted application in Jira GUI, enabling the 2-legged OAuth option
  • Send requests as usual (do not worry about request tokens and access tokens, but include the following parameters in the query string of your request):
    • oauth_consumer_key - the name of your consumer set in the trusted application setup through Jira GUI
    • oauth_token - leave empty
    • oauth_signature_method - RSA-SHA1 is the only method supported by Jira
    • oauth_signature - generate the signature for your request using your private key. For Java users, consider using the net.oauth classes as shown in the Jira OAuth example ()
    • oauth_timestamp - this can be generated automatically with net.oauth
    • oauth_nonce - also generate automatically as above
    • user_id - optional. If specified, Jira will execute the RESTful request as the specified user. If not provided, Jira will use the user specified in the trusted application configuration.

It is worth noting that Martin's explanation is geared towards Java clients using Jersey. The same can be achieved with JavaScript, but be cautious as it may expose the private access token to Confluence, allowing unauthorized individuals to make requests on behalf of your application. It is recommended to handle this securely on the server-side to protect the API key.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Adjusting the contenteditable feature to place the caret on a specific child node

I am experiencing some challenges when attempting to position the cursor after an <i> tag within a contenteditable element. Currently, this is what I have: <p contenteditable="true"><i>H</i><i>e</i><i>l</i> ...

Adding values to an array with the click of a submit button in React JS

I have a unique challenge with creating a form that includes custom inputs. const Input = (props) => { return ( <div> <label className={classes.label}>{props.label} <input className={classes.input} {... ...

What is the process of incorporating a JavaScript node module into TypeScript?

Having trouble importing the xml2js module as I keep getting a 404 error stating that it's not found. import xml2js from 'xml2js'; Any suggestions on how to properly import JavaScript modules located in the node_modules directory when work ...

How to interact with AngularJS drop-down menus using Selenium in Python?

I have been working on scraping a website to create an account. Here is the specific URL: Upon visiting the site, you need to click on "Dont have an account yet?" and then click "Agree" on the following page. Subsequently, there are security questions th ...

Adding embedded attributes from a different object

I am facing a challenge with two arrays called metaObjects and justObjects. These arrays consist of objects that share a common property called id. My goal is to merge properties from the objects in these separate arrays into a new array. const metaObje ...

When attempting to connect to the MongoDB cloud, an unexpected error arises that was not present in previous attempts

npm start > <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="650800170b4816001713001725544b554b55">[email protected]</a> start > nodemon index.js [nodemon] 3.0.2 [nodemon] to restart at any time, enter ...

c# JavaScriptConverter - understanding the deserialization of custom properties

I'm facing an issue where I have a JSON serialized class that I am trying to deserialize into an object. For example: public class ContentItemViewModel { public string CssClass { get; set; } public MyCustomClass PropertyB { get; set; } } Th ...

Tips for Managing the Hardware Back Button in Ionic 3

Can someone help me enable the hardware back button in Ionic 3? I want it to redirect to specific pages and display designated content. Being new to Ionic 3, I need guidance on how to set up the hardware device buttons for redirection. ...

What is the reason behind router.base not functioning properly for static sources while running 'npm run build' in Nuxt.js?

Customizing Nuxt Configuration const BASE_PATH = `/${process.env.CATEGORY.toLowerCase()}/`; export default { router : { base : BASE_PATH }, } In addition, there is a static source for an image in the component: <img src="/mockups/macbookpro_01. ...

javascript display hide choose among

I am attempting to display another set of options when the user selects a specific item. For example, if the user selects "Products," then a new selection box should appear with different product types. See my code below: <html> <head> <m ...

Harness the power of $compile within the Angular link function while also retrieving and utilizing the arguments of the

I am currently developing a custom directive in angular.js 1.x Here is how I call the directive: <mydirective dirarg={{value-1}}></mydirective> My goal is to define the directive by including code to alter the DOM within the directive's ...

Implementing dynamic keys in a JSON data structure with Node.js

Specifically focused on utilizing Node.js ES6 capabilities. I am currently working on creating a JSON document for insertion into a MongoDB database. The keys for inserting the document will be derived from the input values provided. For instance, Here i ...

Using JSF components `h:inputFile` and `f:ajax` for file input

I'm feeling a bit confused. I wanted to create a simple example where we can upload a file from an XHTML page and display something.jpg while the file is being uploaded. Here's what I did: <h:outputScript library="javascript" name="showProgre ...

Following the upgrade of Angular, the webpack module source-map-loader is encountering an error: "this.getOptions is not a function"

Currently in the process of constructing my angular project using webpack alongside source-map-loader to extract source maps, like this: module.exports = { // ... module: { rules: [ { test: /\.js$/, enforce: "pre&quo ...

Ensuring the screen reader shifts focus to the previous element

Utilizing the screen reader to redirect focus back to the previous element has proven to be a challenge for me. After clicking the Return button, it will vanish and the Submit button will take its place. If the Submit button is then clicked, it disappears ...

Searching for a deeply nested JSON property with lodash

I am dealing with a JSON API response that has the following structure: [ { title: "top1", sections: [ { section_title: "section1", content: [ { content_title: "title1", content_id: "id1" ...

ReactJS: The input is not triggering the onChange event

Take a look at this code snippet: import React, { Component, useImperativeHandle } from 'react'; class SearchBar extends Component { render() { return <input onChange={this.onInputChange} />; } onInputChange(event) { console.log(event) } ...

What is the best way to deactivate a button using AngularJS?

$scope.date = moment(currentDate); $scope.date1 = moment(currentDate).add(-1, 'days'); function checkDate(){ if ($scope.date > $scope.date1) { return true; } else{ return false; } }; checkDate(); ...

Replace the default focus state using CSS or resetting it to a custom style

I'm looking for a solution similar to a CSS reset, but specifically for the :focus state. If such a thing doesn't exist yet, I'm interested in learning about the possible properties that can be reset or overridden in order to create a new :f ...

Modify the hash URL in the browser address bar while implementing smooth scrolling and include the active class

I have implemented a smooth scroll technique found here: https://css-tricks.com/snippets/jquery/smooth-scrolling/#comment-197181 $(function() { $('a[href*=#]:not([href=#])').click(function() { if (location.pathname.replac ...