Hello,
I'm trying to authenticate using OAuth2 with a Google account. Currently I'm doing it like this:
let client_id = chrome.runtime.getManifest().oauth2.client_id;
let redirect_uri = chrome.identity.getRedirectURL(); // of the form https://<extension-id>.
chromiumapp.org/ let scope = chrome.runtime.getManifest().oauth2.scopes.join(' ');
let auth_params = {
client_id,
redirect_uri,
response_type: 'token',
scope
};
AUTH_URL += '?' + objToSearchParams(auth_params);
chrome.identity.launchWebAuthFlow({
url: AUTH_URL,
interactive: true
}, function(redirectURL: string) {
if (chrome.runtime.lastError) {
console.error(chrome.runtime.lastError);
} else {
let q = redirectURL.substr(redirectURL.indexOf('#') + 1);
let parts = q.split('&');
for (let i = 0; i < parts.length; i++) {
let kv = parts[i].split('=');
if (kv[0] === 'access_token') {
const token = kv[1];
console.log('token is', token);
}
}
}
});
When running this, in the background.js script, I'm getting an error of the form: {message: "Authorization page could not be loaded."}.
When navigating to the AUTH_URL I'm getting a more sensible error message: 400. That’s an error. Error: redirect_uri_mismatch.
The client_id that I used was copied from
https://console.developers.google.com/apis/credentials/oauthclient/..., for a Chrome App(so not a Web Application, which has a client_secret-I also tried these ids, just to get an error about the client_secret not being an allowed param in the AUTH_URL-).
What am I doing wrong?
PS: I can't use the chrome.identity.getAuthToken flow because it is based on the account that's currently logged in in the Chrome browser(which requires periodical re-logins for accounts other than the one currently logged in into the browser).
Thank you in advance,