小编zor*_*rac的帖子

chrome.identity.launchWebAuthFlow,如何清除用户缓存?

我正在开发可与Gmail一起使用的扩展程序,并且希望能够允许用户在Gmail帐户之间进行切换,并且仍然使用Google REST API。

我正在使用chrome.identity.launchWebAuthFlow获取对Google API的OAuth2访问令牌。

此工作流程将打开一种样式化的chrome webview。顶部没有网址栏。第一次输入用户名和密码,然后允许请求的范围时,Web视图将关闭。然后,我的应用程序会收到包含访问令牌的重定向URI。大。

切换用户时出现问题。有人会认为,这就像检查新电子邮件已登录,然后再次执行chrome.identity.launchWebAuthFlow来获取新令牌一样简单。

不幸的是,第一个登录的用户似乎仍保留在系统中。

function webAuthFlow(userEmail, forceApprovalPrompt, xhrCallback) {
  var baseUrl = 'https://accounts.google.com/o/oauth2/auth';
  var forceApprovalPrompt = forceApprovalPrompt || 'auto';
  var urlParams = {
    'redirect_uri' : 'https://inobjcmbajbmllkgkigemcfnikdmlidn.chromiumapp.org/callback',
    'response_type' : 'token',
    'client_id' : 'not shown here',
    'scope' : 'https://mail.google.com/ https://www.google.com/m8/feeds/',
    'approval_prompt' : 'force',
    'include_granted_scopes' : 'true'
  };

  var providerDetails = {
    url : baseUrl + '?' + stringify(urlParams),
    interactive : true
  }
  var xhrCallback = xhrCallback || false;
  console.log(xhrCallback);
  var callback = function(responseUrl) {
    var params = …
Run Code Online (Sandbox Code Playgroud)

javascript google-chrome-extension oauth-2.0

5
推荐指数
1
解决办法
1615
查看次数

Chrome扩展程序的GMail API访问?403禁止

我有一个应用程序可以通过此处列出的工作流程从Chrome扩展程序访问Google API.

Chrome扩展程序OAuth教程

工作流的基础是初始化OAuth流

var oauth = ChromeExOAuth.initBackgroundPage({
    'request_url': 'https://www.google.com/accounts/OAuthGetRequestToken',
    'authorize_url': 'https://www.google.com/accounts/OAuthAuthorizeToken',
    'access_url': 'https://www.google.com/accounts/OAuthGetAccessToken',
    'consumer_key': '{MY_CLIENT_ID}',
    'consumer_secret': '{MY_CLIENT_SECRET}',
    'scope': 'https://www.google.com/m8/feeds/ https://apps-apis.google.com/a/feeds/emailsettings/2.0/ https://mail.google.com/',
    'app_name': 'Gmail Plugin',
    'callback_page': 'src/google-oauth/chrome_ex_oauth.html'
});
Run Code Online (Sandbox Code Playgroud)

安装扩展程序后,用户将进入对话框页面进行身份验证并同意我要求的范围.从这里我推断我的消费者密钥和秘密是好的.我已允许在Google Developers控制台中访问GMail,Contacts和Admin SDK.

在此之前,我曾要求使用Contacts API和Admin SDK API.我现在正在尝试添加一些使用Gmail REST API的功能.

设置请求的下一步是从后台页面发出请求.

function getSentEmails() {
  var emailCollection; 
  var url = "https://www.googleapis.com/gmail/v1/users/me/messages";
  var request = {
    'method': 'GET',
    'parameters': {
      'labelIds': 'SENT'
    }
  };
  var callback = function(response, xhr) {
    emailCollection = JSON.parse(response);
    console.dir(emailCollection);
  } 
  oauth.sendSignedRequest(url, callback, request);
};
Run Code Online (Sandbox Code Playgroud)

签名请求的工作方式是调用方法来完成OAuth舞的下一步,

oauth.authorize(function() {
    getSentEmails();
  });
Run Code Online (Sandbox Code Playgroud)

这导致每次403禁止.我似乎没有问题访问我提到的其他API虽然这个OAuth流程.我已经在manifest.json中允许了范围 …

javascript google-chrome-extension google-oauth gmail-api

2
推荐指数
1
解决办法
1314
查看次数