Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/api v2 auth #141

Closed
wants to merge 62 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
2688257
login and set user_id from cookie
trickpattyFH20 Jun 6, 2018
f09b82c
store cookie and user login info
trickpattyFH20 Jun 7, 2018
60bbcb2
send login data to view
trickpattyFH20 Jun 7, 2018
ae132f3
- add CSRF cookie
trickpattyFH20 Jun 8, 2018
2d9edc3
csrf token fix cookie name
trickpattyFH20 Jun 8, 2018
22336d0
fix return fetch
trickpattyFH20 Jun 8, 2018
aa708e6
err handle for missing cookie
trickpattyFH20 Jun 8, 2018
392d9ee
lint
trickpattyFH20 Jun 8, 2018
53f8b4f
pull settings
trickpattyFH20 Jun 12, 2018
5942c8d
v2 loggout
trickpattyFH20 Jul 6, 2018
74ab458
settings conf and fix hanging promise
trickpattyFH20 Jul 10, 2018
258c2bf
pull user settings
trickpattyFH20 Jul 10, 2018
6583b4c
move api js from panel to background
trickpattyFH20 Jul 11, 2018
810c7d8
lint
trickpattyFH20 Jul 11, 2018
1d3423b
Enable log in init from the website.
jsignanini Jul 12, 2018
ee54389
Move auth/account domains to globals.
jsignanini Jul 12, 2018
885abf9
pull user settings on login and init
trickpattyFH20 Jul 12, 2018
545c6b5
lint
trickpattyFH20 Jul 12, 2018
dbb9941
Implement logout.
jsignanini Jul 12, 2018
f88d3a2
Implement send verify email.
jsignanini Jul 12, 2018
31df7c8
login data success missing
trickpattyFH20 Jul 12, 2018
e6d964c
Merge branch 'feature/api-v2-auth' of github.com:ghostery/ghostery-ex…
trickpattyFH20 Jul 12, 2018
260d988
pushUserSettings and remove unused
trickpattyFH20 Jul 12, 2018
d00a1eb
Implement create account v2.
jsignanini Jul 12, 2018
99da32f
Fix logout from platform pages not sending message to background.
jsignanini Jul 12, 2018
ac0213d
remove api from panel
trickpattyFH20 Jul 12, 2018
8fb4e18
Merge branch 'feature/api-v2-auth' of github.com:ghostery/ghostery-ex…
trickpattyFH20 Jul 12, 2018
b1f78fa
Fix missing function.
jsignanini Jul 12, 2018
cd56624
Merge branch 'feature/api-v2-auth' of github.com:ghostery/ghostery-ex…
jsignanini Jul 12, 2018
a695d77
Add error handling for v2 login.
jsignanini Jul 12, 2018
a584db6
move userLogin fetch to background
trickpattyFH20 Jul 12, 2018
70f62ff
forgot password email
trickpattyFH20 Jul 13, 2018
1a43e2f
fix lgmogout
trickpattyFH20 Jul 13, 2018
b988746
fix legacy settings conf
trickpattyFH20 Jul 13, 2018
8135136
setup login
trickpattyFH20 Jul 13, 2018
4172242
setup createAccount
trickpattyFH20 Jul 13, 2018
beb276d
move createAccount fetch
trickpattyFH20 Jul 13, 2018
1572834
Several refactors and fixes.
jsignanini Jul 13, 2018
49bf9b1
Remove catch from logout.
jsignanini Jul 16, 2018
02981a8
account actions unit tests
trickpattyFH20 Jul 16, 2018
dc44e85
Merge branch 'feature/api-v2-auth' of github.com:ghostery/ghostery-ex…
trickpattyFH20 Jul 16, 2018
c6f2f16
lint
trickpattyFH20 Jul 16, 2018
1348cb7
Further refactor.
jsignanini Jul 16, 2018
d18d847
Refactor account.register.
jsignanini Jul 16, 2018
5e547e2
Refactor send validate account email.
jsignanini Jul 16, 2018
5418b62
Refactor reset password.
jsignanini Jul 17, 2018
a525f8d
More refactoring.
jsignanini Jul 17, 2018
0c7e1d8
fix unit test
trickpattyFH20 Jul 17, 2018
7027d39
Merge branch 'feature/api-v2-auth' of github.com:ghostery/ghostery-ex…
trickpattyFH20 Jul 17, 2018
8032ca3
Linter fix.
jsignanini Jul 17, 2018
ac8eee0
fix login_info unit tests
trickpattyFH20 Jul 17, 2018
8b455a1
Add specific babel-loader for background source files.
jsignanini Jul 18, 2018
9fb0e71
refresh token logout handler - api as class
trickpattyFH20 Jul 18, 2018
82f499e
export _getJSONAPIErrorsObject - move getCsrfCookie to api
trickpattyFH20 Jul 18, 2018
c6836b9
lint
trickpattyFH20 Jul 18, 2018
ce0b31f
Refactor account into own component.
jsignanini Jul 18, 2018
f17f476
Move logged in check into Account class. Cleanup.
jsignanini Jul 18, 2018
beef14e
Refactor account in setup page.
jsignanini Jul 19, 2018
b570527
Refactor setup page header log in.
jsignanini Jul 19, 2018
07ab815
Merge branch 'develop' into feature/api-v2-auth
jsignanini Jul 19, 2018
220cec8
lint - use logger in ExtMessenger
trickpattyFH20 Jul 19, 2018
b550262
update tests
trickpattyFH20 Jul 19, 2018
File filter
Filter file types
Jump to
Jump to file
Failed to load files.

Always

Just for now

- add CSRF cookie
- remove token from src
- add name to login_info
  • Loading branch information
trickpattyFH20 committed Jul 6, 2018
commit ae132f33a7783698942605000dd709559f2bc574
@@ -137,6 +137,7 @@ export function fetchUser(user_id) {
type: LOGIN_DATA_SUCCESS,
data: user,
});
return user;
})
.catch(e => {
console.error(e);
@@ -4,6 +4,9 @@ import 'whatwg-fetch';
let isRefreshing = false;
const tokenRefreshedEventType = 'tokenRefreshed';
const Config = {
auth_server : {
host: 'http://ghostery.io:8080'
},
account_server : {
host: 'http://ghostery.io:8081'
},
@@ -31,18 +34,29 @@ const _refreshToken = function () {
});
};

const _sendReq = (method, path, body) => (
fetch(`${Config.account_server.host}${path}`, { // eslint-disable-line no-undef
method,
headers: {
'Content-Type': 'application/vnd.api+json',
'Content-Length': Buffer.byteLength(JSON.stringify(body)),
'X-CSRF-Token': '' // TODO get cookie from conf,
},
body: JSON.stringify(body),
credentials: 'include',
})
);
const _sendReq = (method, path, body) => {
return new Promise((resolve, reject) => {
chrome.cookies.get({
url: 'http://ghostery.io', // ghostery.com || ghosterystage.com
name: 'user_id',
}, (cookie) => {
if (cookie) {
fetch(`${Config.account_server.host}${path}`, { // eslint-disable-line no-undef
method,
headers: {
'Content-Type': 'application/vnd.api+json',
'Content-Length': Buffer.byteLength(JSON.stringify(body)),
'X-CSRF-Token': cookie.value,
},
body: JSON.stringify(body),
credentials: 'include',
});
} else {
reject();
}
});
});
}

const _processResponse = res => (
new Promise((resolve, reject) => {
@@ -149,9 +149,7 @@ class ConfData {
_initProperty('login_info', {
logged_in: false,
email: '',
user_token: '',
decoded_user_token: {},
is_validated: false
user_id: '',
});
});
}
@@ -169,7 +169,6 @@ class PanelData {
get panelView() {
this._panelView = {
panel: {
decoded_user_token: this._confData.get('decoded_user_token'),
email: this._confData.get('email'),
enable_ad_block: this._confData.get('enable_ad_block'),
enable_anti_tracking: this._confData.get('enable_anti_tracking'),
@@ -188,6 +187,7 @@ class PanelData {
smartBlock: this._trackerData.get('smartBlock'),
tab_id: this._trackerData.get('tab_id'),
unread_offer_ids: rewards.unreadOfferIds,
user_id: this._confData.get('user_id'),
},
summary: this.summaryView,
blocking: this._confData.get('is_expert') ? this.blockingView : false,
@@ -301,7 +301,6 @@ class PanelData {
.set('block_by_default', conf.block_by_default)
.set('bugs_last_updated', conf.bugs_last_updated)
.set('categories', this._buildGlobalCategories())
.set('decoded_user_token', login_info.decoded_user_token)
.set('email', login_info.email)
.set('enable_ad_block', conf.enable_ad_block)
.set('enable_anti_tracking', conf.enable_anti_tracking)
@@ -312,14 +311,14 @@ class PanelData {
.set('enable_metrics', conf.enable_metrics)
.set('enable_offers', conf.enable_offers)
.set('enable_smart_block', conf.enable_smart_block)
.set('first_name', (login_info.decoded_user_token && login_info.decoded_user_token.ClaimFirstName))
.set('first_name', login_info.first_name)
.set('hide_alert_trusted', conf.hide_alert_trusted)
.set('ignore_first_party', conf.ignore_first_party)
.set('is_validated', login_info.is_validated)
.set('is_expanded', conf.is_expanded)
.set('is_expert', conf.is_expert)
.set('language', conf.language)
.set('last_name', (login_info.decoded_user_token && login_info.decoded_user_token.ClaimLastName))
.set('last_name', login_info.last_name)
.set('logged_in', login_info.logged_in)
.set('notify_library_updates', conf.notify_library_updates)
.set('notify_upgrade_updates', conf.notify_upgrade_updates)
@@ -340,6 +339,7 @@ class PanelData {
.set('site_whitelist', conf.site_whitelist)
.set('toggle_individual_trackers', conf.toggle_individual_trackers)
.set('trackers_banner_status', conf.trackers_banner_status)
.set('user_id', login_info.user_id)
.set('expand_all_trackers', conf.expand_all_trackers);
}

@@ -60,14 +60,16 @@ const SYNC_SET = new Set(globals.SYNC_ARRAY);
* @return {Promise} login info object
*/
export function setLoginInfo(user) {
console.log('inside background setLoginInfo', user);
console.log('background setLoginInfo', user);
return new Promise((resolve, reject) => {
const { email, emailValidated, id } = user;
const { email, emailValidated, id, firstName, lastName } = user;
conf.login_info = {
logged_in: true,
user_id: id,
is_validated: emailValidated,
email
email,
first_name: firstName,
last_name: lastName,
};
resolve(conf.login_info);
});
ProTip! Use n and p to navigate between commits in a pull request.