如何在用户登录gmail之前限制用户登录到特定域。我正在创建一个chrome扩展,只允许域名。我已经使用oauth2来获取令牌,但这是在用户登录之后。我在chrome扩展名的oauth下的manifest.json中添加了“hd”:“domain.com”,但是它从所有gmail用户获取令牌。
的manifest.json
{
"manifest_version": 2,
"name": "BT_auth",
"short_name": "BT_auth",
"description": "",
"version": "0.0.1",
"minimum_chrome_version": "38",
"icons": {
"16": "assets/icon_16.png",
"128": "assets/icon_128.png"
},
"app": {
"background": {
"scripts": ["background.js"]
}
},
"permissions" : [
"identity"
],
"oauth2" : {
"client_id" : "**********",
"scopes" : [
"https://www.googleapis.com/auth/userinfo.profile"
],
"access_type" : "online",
"hd" : "browntape.com"
},
"key" : "***********"
}
的index.html
<!DOCTYPE html>
<html>
<body>
<div id = "button"
style = "padding : 8px;
background-color: yellow;
display: inline-block;">
Gmail Access!!
</div>
<script src="main.js"></script>
</body>
</html>
main.js
window.onload = function() {
document.querySelector("#button").addEventListener("click",function(){
chrome.identity.getAuthToken({"interactive" : true}, function(token){
console.log(token);
})
})
};
background.js
chrome.app.runtime.onLaunched.addListener(function(launchData) {
chrome.app.window.create('index.html',{
id: 'mainWindow',
bounds: {width: 800, height: 600}
}
);
});