Access user authorizationServer key from studio



  • Hello everyone!

    Currently I'm trying to setup communication between my own app and jsreport.
    I was able to authenticate my users in jsreport through authorizationServer and now have sql table with their oauth keys.

    What I need to do now it is to use my app's API from jsreport studio scripts. I need this calls to be made from current user using studio. Can I somehow access his auth key?


  • administrators

    hi!

    What I need to do now it is to use my app's API from jsreport studio scripts. I need this calls to be made from current user using studio. Can I somehow access his auth key?

    this depends on how your app's API authenticates the call, what does it expect? is it a token in the Authorization header? i am not clear what specific value from authorizationServer you want to reuse



  • Hey! Thanks for reply!

    Since I have full control of my app I am flexible on that part. Since we use extensions authentication authorizationServer and already generate and return access_token to jsreport I thought that maybe it can be used for reverse authentication for API calls from studio.
    But once again, I can adapt to other strategy if there is one. The main goal is to authenticate user specific API calls from studio to my app without master login/password for all requests.


  • administrators

    Since we use extensions authentication authorizationServer and already generate and return access_token to jsreport I thought that maybe it can be used for reverse authentication for API calls from studio.

    so, do you want to reuse such access token and use it for api calls from scripts?

    if you enable the extensions.express.exposeHttpHeaders to true then you can get the headers that contains the token from script.

    in the script you can do this, can work with the header to extract the token from there

    async function beforeRender (req, res) {
        // you can also log all the headers so you better understand what it is in there
        console.log(JSON.stringify(req.context.http.headers, null, 2 ))
        const authorizationHeader = req.context.http.headers.authorization
        console.log(authorizationHeader) // should log "Bearer xxxxxx"
    }
    

Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.