JSON 웹 토큰을 사용하여 Chrome 확장 프로그램에서 내 앱으로 POST 요청을 인증하는 방법은 무엇입니까? (How to authenticate a POST request from a chrome extension to my app with JSON web tokens?)


문제 설명

JSON 웹 토큰을 사용하여 Chrome 확장 프로그램에서 내 앱으로 POST 요청을 인증하는 방법은 무엇입니까? (How to authenticate a POST request from a chrome extension to my app with JSON web tokens?)

컨텍스트

내 HapiJS 웹 애플리케이션은 현재 OAuth 2.0을 사용하여 Google API에 액세스하고 있습니다. 사용자가 앱에서 인증하면 서버는 클라이언트에 저장되고 후속 요청의 Authorization 헤더로 다시 전송되는 JSON 웹 토큰(JWT)을 생성합니다.

내가 달성하고 싶은 것

이제 Google Chrome 확장 프로그램을 통해 동일한 단계(승인 + JWT 생성)를 사용하여 데이터를 다시 앱으로 동기화하고 싶습니다. REST 끝점.

현재 생각

내 아이디어는 JWT를 생성한 다음 저장하기 위해 내 애플리케이션에 있는 것과 동일한 OAuth 인증을 사용하는 것입니다. JWT를 Chrome 확장 프로그램에 추가합니다.


참조 솔루션

방법 1:

You can use your localStorage to save your jwt from the web app, then, if your extension runs on the same domain, you can access saved information from the localStorage through a content script, that gets injected in that page. You can communicate with your popup using the Message Passing API for Chrome extensions.

The problem with this approach comes with the fact that saving sensible information like user info (which is encoded in the jwt) is frowned upon due to security concerns.

Ideally, you should have a server which handles the authentication back and forth, saves the information and emits a session token for its clients, which then you can save in the localStorage if you wish.

방법 2:

If you want your popup.html to contain a link to allow users to open (leading to OAuth Google in your model), you need more work than a simple anchor link.

You will need to add event listeners to the link and use chrome.tabs.create.

Here is a demo code:

popup.html

<html>
    <body>
        <span class="link" data‑href="https://www.google.com">link</span>
        <span class="link" data‑href="https://www.bing.com">link</span>
        <span class="link" data‑href="https://www.yahoo.com">link</span>

        <script>

            //get all links
            var links = document.getElementsByClassName('link');

            //loop through each link
            for (var ii = 0, nn = links.length; ii < nn; ii++)
            {
                //add listener
                links[ii].addEventListener('click', function(e)
                {
                    //grab link
                    var url = this.getAttribute('data‑href');

                    //open link in new tab using chrome.tabs.create method
                    chrome.tabs.create({url:url});
                });
            }
        </script>
    </body>
</html>

(by AnitaAvram TudorJoseph Shih)

참조 문서

  1. How to authenticate a POST request from a chrome extension to my app with JSON web tokens? (CC BY‑SA 2.5/3.0/4.0)

#OAuth #authentication #javascript #jwt #google-chrome-extension






관련 질문

포도 API 및 OAuth (Grape API and OAuth)

단일 사용자 계정에 대해 동일한 타사 애플리케이션을 여러 번 승인하는 방법은 무엇입니까? (How to handle authorizing the same third-party application multiple times for a single user account?)

Google OAuth의 액세스 토큰 만료 시간대 (Google OAuth's access token's expiry timezone)

Facebook에서 앱 ID를 얻는 방법 (How to get app id on Facebook)

새로 고침 토큰을 사용하여 백그라운드에서 인증을 받고 액세스 토큰을 얻는 방법은 무엇입니까? (How to use refresh token to get authorized in background and getting access token?)

JSON 웹 토큰을 사용하여 Chrome 확장 프로그램에서 내 앱으로 POST 요청을 인증하는 방법은 무엇입니까? (How to authenticate a POST request from a chrome extension to my app with JSON web tokens?)

LAN 내부에 인증 자동 기능이 있는 Grails 애플리케이션을 테스트할 수 없습니다. (Cannot test Grails application which has oauth autontication inside LAN)

신뢰할 수 없는 호스트를 사용하여 방화벽에서 보안 연결을 중개하는 방법은 무엇입니까? (How to broker secure connection across firewalls using untrusted host?)

로컬 HTML 파일에서 oAuth 흐름을 처리합니까? (Handling an oAuth flow from local HTML files?)

Twitter4J로 인증하는 방법은 무엇입니까? (how to authenticate with Twitter4J?)

IdentityServer4를 사용할 때 "코드 챌린지 필요" 메시지가 나타납니다. (I am getting "code challenge required" when using IdentityServer4)

Apache Superset 및 Auth0은 "브라우저(또는 프록시)가 이 서버가 이해할 수 없는 요청을 보냈습니다."를 반환합니다. (Apache Superset and Auth0 returns "The browser (or proxy) sent a request that this server could not understand.")







코멘트