1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-21 18:53:29 +00:00

handle traferring old auth bearer

This commit is contained in:
Kyle Spearrin
2017-01-21 22:00:02 -05:00
parent e1ed7587dc
commit 4968a00dcf
2 changed files with 95 additions and 33 deletions

View File

@@ -4,6 +4,7 @@
function initTokenService() {
var _token,
_authBearer,
_decodedToken,
_refreshToken;
@@ -52,6 +53,24 @@ function initTokenService() {
});
};
TokenService.prototype.getAuthBearer = function (callback) {
if (!callback || typeof callback !== 'function') {
throw 'callback function required';
}
if (_authBearer) {
return callback(_authBearer);
}
chrome.storage.local.get('authBearer', function (obj) {
if (obj && obj.authBearer) {
_authBearer = obj.authBearer;
}
return callback(_authBearer);
});
};
TokenService.prototype.setRefreshToken = function (refreshToken, callback) {
if (!callback || typeof callback !== 'function') {
throw 'callback function required';
@@ -83,15 +102,28 @@ function initTokenService() {
});
};
TokenService.prototype.clearAuthBearer = function (callback) {
if (!callback || typeof callback !== 'function') {
throw 'callback function required';
}
_authBearer = null;
chrome.storage.local.remove('authBearer', function () {
callback();
});
};
TokenService.prototype.clearToken = function (callback) {
if (!callback || typeof callback !== 'function') {
throw 'callback function required';
}
_token = _decodedToken = _refreshToken = null;
chrome.storage.local.remove('accessToken', function () {
chrome.storage.local.remove('refreshToken', function () {
callback();
_token = _decodedToken = _refreshToken = _authBearer = null;
chrome.storage.local.remove('authBearer', function () {
chrome.storage.local.remove('accessToken', function () {
chrome.storage.local.remove('refreshToken', function () {
callback();
});
});
});
};