Chrome Extension Authorization page could not be loaded

Viewed 578

I'm trying to authorize with Cognito in my Chrome Extension using chrome.identity.launchWebAuthFlow.

Manifest.JSON file

{
"manifest_version": 2,
"name": "app",
"permissions": [
    "http://*/*", "tabs", "webNavigation", "activeTab", "storage", "identity",
    "declarativeContent", "https://****.eu-west-2.amazoncognito.com/oauth2/authorize/*"
],
"version": "0.7.5",
"content_scripts": [{
    "js": ["src/content.js"],
    "matches": [
        "*://docs.google.com/spreadsheets/*"
    ]
}],
"background": {
    "scripts": ["src/backgroundOauth.js"],
    "persistent": false
},
"browser_action": {
    "default_popup": "popup.html",
},
"oauth2": {
    "client_id": CLIENT_ID,
    "scopes": [
        "openid", "email", "profile", "aws.cognito.signin.user.admin"
    ]
}

}

BackgroundOauth.js

    const URI = chrome.identity.getRedirectURL();
const CLIENT_ID = <CLIENT_ID>;
chrome.identity.launchWebAuthFlow({
        "url": "https://<secret>.auth.eu-west-2.amazoncognito.com/oauth2/authorize?" + CLIENT_ID +
            "&redirect_uri=" + encodeURIComponent(URI) +
            "&response_type=code",
        'interactive': true,
    },
    function(redirect_url) {
        console.log(redirect_url);
    });

After install and run, output log 'Authorization page could not be loaded.'.

redirect_url inside of launchWebAuthFlow is undefined.

I have listed my cognito settings as well to see if it something wrong with Cognito setup instead of Chrome issue. Anyone who can help me on this I'll be extremely grateful.

Image of my Cognito Pool settings

1 Answers

Resolved in another thread. Issue is missing client_id= key inside of query string

Fixed code:

const URI = chrome.identity.getRedirectURL();
const CLIENT_ID = <CLIENT_ID>;
chrome.identity.launchWebAuthFlow({
    "url": "https://<secret>.auth.eu-west-2.amazoncognito.com/oauth2/authorize" +
        "?client_id=" + encodeURIComponent(CLIENT_ID) +
        "&redirect_uri=" + encodeURIComponent(URI) +
        "&response_type=code",
    'interactive': true,
},
function(redirect_url) {
    console.log(redirect_url);
});

Relevant docs: https://docs.aws.amazon.com/cognito/latest/developerguide/authorization-endpoint.html

Related