Welcome to the Panopto Community

Please note: All new registrants to the Panopto Community Forum must be approved by a forum moderator or admin. As such, if you navigate to a feature that is members-only, you may receive an error page if your registration has not yet been approved. We apologize for any inconvenience and are approving new members as quickly as possible.

Examples of node.js implementation? oAuth process

Hi all,


I've been trying to figure out how to access the sessionUpload API via node.js. I have an API key and secret and think I'm sending the correct request to get oAuth token.

I'm using the Axios fetch library to do this, see example code below:

////

const API_TOKEN = Buffer.from(`${PANOPTO_API_ID}:${PANOPTO_API_SECRET}`, "utf8").toString("base64");

PANOPTO_AXIOS.post("oauth2/connect/token", {

params: {

grant_type: "client_credentials",

scope: "api",

},

headers: {

Authorization: `Basic ${API_TOKEN}`,

"Content-Type": "application/x-www-form-urlencoded",

},

}).then((response) => console.log(response)).catch((err) => console.log(err));

////

I keep getting a 415 "Unsupported media type" error:

And this is all just to get an oAuth token before I can start using the sessionUpload API.

Any guidance would be much appreciated!

Thanks,

Phil

Tagged:

Answers

  • Kevin BaumKevin Baum Panopto Employee

    Hi Phil,

    This may be due to the Axios library not sending the POST body with the request when it is expected. I believe that the "params" property in Axios is used for URL Parameters.

    Can you try changing the "params" object to a "data" object instead and see if that helps with the Unsupported Media Type error?

    Please let me know if you have any other questions.

    Thanks,

    Kevin

  • Hi Kevin,

    Thanks for your reply but that doesn't appear to be working.

    Changed code:

    PANOPTO_AXIOS.post("oauth2/connect/token", {

    data: {

    grant_type: "client_credentials",

    scope: "api",

    },

    headers: {

    Authorization: `Basic ${API_TOKEN}`,

    "Content-Type": "application/x-www-form-urlencoded",

    },

    })

    This is giving the same error.

    Anymore ideas?

  • Maybe if I change my question and ask what the best approach is for the following scenario: a process running on a server that will download video data from one source and then upload to Panopto. I do not expect any user interaction besides myself and hoping this service will run mostly automated.

    NodeJS is what I know best which is why I want to use it to implement the above.

    I have videographer access to my instance of Panopto and can see the API clients section.

    My question becomes:

    What's the best API client type for my situation?

    Is there any example code for NodeJS implementation?

    I'm assuming you don't have a straightforward API that can be accessed with just an API key + secret, i.e. you must go oauth route to get access token?

    Thanks,

    Phil

  • Kevin BaumKevin Baum Panopto Employee

    Hi Phil,

    With the change from params to data, are you still getting the "415 Unsupported Media" error? If so, it may still be something in the Axios library that is not correctly sending the body content causing that error.

    Regarding your second question, most of our REST APIs require a user to authenticate in order to verify permissions before viewing, creating, modifying, or deleting content. For uploading content, we do require a user to allow the operation.

    If your upload service will be running without direct user interaction, the best suggestion is to create a "User Based Server Application" to use. You can then create an internal user in Panopto that would be allowed to create content in the folder(s) that you will be uploading to. You could then use the credentials for this new user to get an access token. We have more information on how to use a User Based Server Application to get an access token for a service in section 2.1 of this support article:

    We do not currently have any public samples to implement the API with NodeJS, but we are working to add more samples in the future. I was able to quickly get a sample for getting an access token using a User Based Server Application Client with Axios from Node for you though.

    let url = the URL to the token endpoints (i.e. https://<your-Panopto-server>/Panopto/oauth2/connect/token)

    axios({

        method: 'post',

        url: url,

        headers: {

            "Authorization": `Basic ${API_TOKEN}`,

            "Content-Type": "application/x-www-form-urlencoded"

        },

        data: "grant_type=password&scope=api&username=REDACTED&password=REDACTED"

    }).then(function(response) {

        console.log(response.data);

    }).catch(function(error) {

        console.log("error: " + error);

    });

    Please let me know if you have any other questions.

    Thanks,

    Kevin

  • Hi Kevin,

    Thank you for providing some sample code. I've tried it and receiving error 400 so I'm assuming either my API_TOKEN, username or password is incorrect.

    Assuming my API_TOKEN code is correct:

    const API_TOKEN = Buffer.from(`${PANOPTO_API_ID}:${PANOPTO_API_SECRET}`, "utf8").toString("base64");

    So probably means the username or password I'm providing is incorrect:

     data: "grant_type=password&scope=api&username=REDACTED&password=REDACTED"

    I'm using template strings (``) to embed the username and password as variables. Do you need to include the provider/domain at the end of my username? e.g. @university.ac.uk?

    Thanks for all of your help so far!

    Phil

  • Kevin BaumKevin Baum Panopto Employee

    Hi Phil,

    Are you logging in using an SSO based account (logging into Panopto through Canvas, BlackBoard, etc.), or using an internal Panopto user account that is not tied to any other systems?

    If you are using an external user account to log in, there is a slightly different way to authenticate a user. Please see section 2.1.c of this support article.

    If you are using an internal Panopto user, or if you're still having trouble logging in with an external account after looking at the support article, we may need you to have your POC open a support ticket. Since this is related to authentication, we may need to get some further details from you to investigate further.

    If you have any other questions, please let me know.

    Thanks,

    Kevin

  • Hi Kevin,

    The account I have requires login via Single Sign On. What's the best course of action?

    Thanks,

    Phil

  • Kevin BaumKevin Baum Panopto Employee

    Hi Phil,

    Using an SSO account with a User Based Server Application is supported, but user authentication is handled slightly different. Instead of sending your third party credentials, you will need to send the Panopto User Key as the username and a generated authentication code for the password.

    The User Key is made up of the ID Provider name from Panopto, followed by a slash, then the username (for example, CanvasIDProvider\[email protected]). The instructions to generate the authentication code to use instead of the password are in section 2.1.c of the following support document:

    If you're already sending the User Key and authentication code, and are still unable to get an access token, please have your POC open a support ticket, so that we may get some additional information from you privately to continue investigating.

    If you have any other questions, please let me know.

    Thanks,

    Kevin

Sign In or Register to comment.