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:
@@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user