Guide to setting up 2-factor authentication on GitHub using an AJAX request

My task is to query GitHub for all open pulls, but I'm new to this and don't have anyone to turn to for guidance. The only resources I've found so far are the documentation on .

I came across a solution on that explains how to provide a username and password. However, I encountered an issue with GitHub's two-factor authentication.

After reading through the GitHub documentation, I found this note:

In addition to the Basic Authentication credentials, you must send the user's authentication code (i.e., one-time password) in the X-GitHub-OTP header.

To solve this, I generated a personal access token and adjusted my code like so:

const auth = getAuth();
$.ajax({
        type: "GET",
        url: "https://api.github.com/repos/company/repo/pulls",            
        dataType: 'json',
        async: true,
        headers: { 
            "Authorization": "Basic " + auth,
            "X-GitHub-OTP": "d......Access...Token.......5"
        }, 
...

However, I keep receiving a fail message with the following error:

Must specify two-factor authentication OTP code.

I thought I included the OTP code in the header, but it seems there's still an issue. I'm not sure where I've gone wrong.

Answer №1

Utilize the X-GitHub-OTP header specifically for a one-time password, which consists of a 6-digit code obtained from either your Authenticator app or via SMS during the login process. This header should not be used for an API token.

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

I attempted to use the Stripe API, but it seems to be non

I seem to be encountering an issue with the stripe.customers.create. My goal is to create a new Stripe customer using the email address of the current user, and then update my user with the generated customer.id. Despite the fact that stripe.customers.cre ...

`Is there a way to sort a deeply nested object by its values?`

I need assistance sorting an array of hospitals based on the lowest value of the amountinINR key, especially when dealing with deeply nested arrays of hospital objects. Does anyone know how to achieve this without using third-party libraries like lodash or ...

"Learn how to capture the complete URL and seamlessly transfer it to another JavaScript page using Node.js and Express.js

Is there a way to access the token variable in another page (api.js)? I need to use it in my index.js. var express = require('express'); var router = express.Router(); router.get('/', function(req, res ...

Trouble encountered when trying to update model using AJAX "POST" request

I am attempting to update my model without having to refresh the entire page. The issue arises when I try to save changes using a wysiwyg inline editor placed in various locations on the page. The structure of the editor can vary, as shown below: <div ...

Utilize the nest function in D3 to organize flat data with a parent key into a hierarchical structure

I'm searching for an elegant and efficient solution to transform my input data into a hierarchical structure using d3.js nest operator. Here is an example of the input data: [ {id: 1, name: "Peter"}, {id: 2, name: "Paul", manager: 1}, {id: 3, name: " ...

Tips for managing encoding when transmitting values through ajax

When working in WordPress, I encountered an issue with an Ajax call where a value was being sent inaccurately. blow = \'blo\ Upon receiving the value on the server end, it appeared to have an extra backslash (\). blow = \\& ...

The pop-up box triggered by Onbeforeunload will not be displayed

Currently, I am in the process of developing a website that includes user profiles. At this stage, I am focusing on the image upload functionality. When a user successfully uploads an image, it is stored in four different folders: one for size 25, 100, 150 ...

Saving information from JSON data obtained through the Google People API

My server is connected to the Google People API to receive contact information, and the data object I receive has a specific structure: { connections: [ { resourceName: 'people/c3904925882068251400', etag: '%EgYBAgkLNy4aDQECAwQFBgcICQoLD ...

Is there a way to initiate a jquery function upon loading the page, while ensuring its continued user interaction?

On my webpage, there is a JavaScript function using jQuery that I want to automatically start when the page loads. At the same time, I want to ensure that users can still interact with this function. This particular function involves selecting a link tha ...

What are the steps to create a shadow effect on a bar chart in ChartJs?

Currently, I am utilizing version 3.9 of chartjs to construct a bar chart. My goal is to incorporate a shadow effect on the bars resembling the image in this link: https://i.sstatic.net/SGIrO.png Despite my efforts, I have not been able to locate instruc ...

Issue with VueJS instance: Unable to prevent default behavior of an event

Is there a way to disable form submission when the enter key is pressed? Take a look at the different methods I've attempted along with the code and demo example provided below. SEE PROBLEM DEMO HERE Intended outcome: When you focus on the input, pr ...

Conducting various calculations and showcasing them all on a single webpage

Uncertain about what to name this, but let's see if you understand my question. I have a table on a standard HTML page and I am performing some calculations using Javascript/jQuery. Example: function addThem() { var result; result = userIn ...

Issues with timing in AJAX within ASP.NET

I am currently working on a web application that requires the use of a countdown timer. I am utilizing asp.net for this project. asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePan ...

What is the process for adding a dot to the package.json file using the npm-pkg command?

I need help using the npm pkg set command to create a package.json file with the following structure: { ... "exports": { ".": { "import": "./dist/my-lib.js", "require": "./dist/my-l ...

Optimizing Your HTML/CSS/JavaScript Project: Key Strategies for Modular

When it comes to web frontend projects (html/css/javascript), they are often perceived as more complex to read and maintain compared to Java/C#/C/C++ projects. Is it possible to outline some optimal strategies for enhancing the readability, modularizatio ...

Using routes with optional parameters can inhibit the loading of other routes

In my Node.js app based on Express, I have implemented three different routes. app.get('/', function (req, res) { // }) app.get('/findOne', function (req, res) { // }) app.get('/getFour', function (req, res) { // }) Init ...

Creating a JavaScript function that increments or decrements a variable based on keyboard input is a useful feature

My goal is to have a count start at 100 and then either count up or down by 1 when a specific keyboard button is pressed. Currently, I am using the keys 8 and 2 on the keypad, which represent ascii numbers 104 and 98. So far, the code I have only allows f ...

Determining the number of words in every line within a textarea

I am looking to determine the number of words per line in a textarea. The width of the textarea is variable. Check out this code snippet that calculates the number of rows: http://jsfiddle.net/2tcygj9e/ ...

React JS Button remains unaltered despite API call influence

I have encountered an issue with my page where a single post is displayed and there is a like button. The problem arises when the user clicks the like button - if the post is already liked, the button state should change to an unlike button. However, if th ...

Understanding JSON Arrays using jQuery

I've been attempting to display JSON objects in the console, but unfortunately, I'm facing some issues. The JSON data is obtained from a small API that I crafted using PHP. Here's a snippet of my JSON: { TotalResults: 2, Results: [ ...