#359: detect unknown oauth scopes on frontend and log if found any. Provide user friendly fallback in case if no translation for some of scopes

This commit is contained in:
SleepWalker 2017-10-17 20:50:34 +03:00
parent 465fa8bec1
commit 64516b8a08
3 changed files with 29 additions and 4 deletions

View File

@ -189,6 +189,12 @@ export function clearErrors() {
return setErrors(null); return setErrors(null);
} }
const KNOWN_SCOPES = [
'minecraft_server_session',
'offline_access',
'account_info',
'account_email',
];
/** /**
* @param {object} oauthData * @param {object} oauthData
* @param {string} oauthData.clientId * @param {string} oauthData.clientId
@ -213,18 +219,27 @@ export function oAuthValidate(oauthData) {
return wrapInLoader((dispatch) => return wrapInLoader((dispatch) =>
oauth.validate(oauthData) oauth.validate(oauthData)
.then((resp) => { .then((resp) => {
const scopes = resp.session.scopes;
const invalidScopes = scopes.filter((scope) => !KNOWN_SCOPES.includes(scope));
let prompt = (oauthData.prompt || 'none').split(',').map((item) => item.trim); let prompt = (oauthData.prompt || 'none').split(',').map((item) => item.trim);
if (prompt.includes('none')) { if (prompt.includes('none')) {
prompt = ['none']; prompt = ['none'];
} }
if (invalidScopes.length) {
logger.error('Got invalid scopes after oauth validation', {
invalidScopes
});
}
dispatch(setClient(resp.client)); dispatch(setClient(resp.client));
dispatch(setOAuthRequest({ dispatch(setOAuthRequest({
...resp.oAuth, ...resp.oAuth,
prompt: oauthData.prompt || 'none', prompt: oauthData.prompt || 'none',
loginHint: oauthData.loginHint loginHint: oauthData.loginHint
})); }));
dispatch(setScopes(resp.session.scopes)); dispatch(setScopes(scopes));
localStorage.setItem('oauthData', JSON.stringify({ // @see services/authFlow/AuthFlow localStorage.setItem('oauthData', JSON.stringify({ // @see services/authFlow/AuthFlow
timestamp: Date.now(), timestamp: Date.now(),
payload: oauthData payload: oauthData

View File

@ -43,9 +43,18 @@ export default class PermissionsBody extends BaseAuthBody {
<Message {...messages.theAppNeedsAccess2} /> <Message {...messages.theAppNeedsAccess2} />
</div> </div>
<ul className={styles.permissionsList}> <ul className={styles.permissionsList}>
{scopes.map((scope, key) => ( {scopes.map((scope) => {
<li key={key}>{<Message {...messages[`scope_${scope}`]} />}</li> const key = `scope_${scope}`;
))} const message = messages[key];
return (
<li key={key}>
{message ? <Message {...message} /> : scope.replace(/^\w|_/g, (match) =>
match.replace('_', ' ').toUpperCase()
)}
</li>
);
})}
</ul> </ul>
</div> </div>
</div> </div>

View File

@ -86,6 +86,7 @@ function _trackPageView(location) {
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
// some shortcuts for testing on localhost // some shortcuts for testing on localhost
window.testOAuth = (loginHint = '') => location.href = `/oauth2/v1/ely?client_id=ely&redirect_uri=http%3A%2F%2Fely.by%2Fauthorization%2Foauth&response_type=code&scope=account_info%2Caccount_email&login_hint=${loginHint}`; window.testOAuth = (loginHint = '') => location.href = `/oauth2/v1/ely?client_id=ely&redirect_uri=http%3A%2F%2Fely.by%2Fauthorization%2Foauth&response_type=code&scope=account_info%2Caccount_email&login_hint=${loginHint}`;
window.testOAuthPermissions = () => location.href = '/oauth2/v1/tlauncher?client_id=tlauncher&redirect_uri=http%3A%2F%2Flocalhost%3A8080&response_type=code&scope=account_info,account_email';
window.testOAuthPromptAccount = () => location.href = '/oauth2/v1/ely?client_id=ely&redirect_uri=http%3A%2F%2Fely.by%2Fauthorization%2Foauth&response_type=code&scope=account_info%2Caccount_email&prompt=select_account'; window.testOAuthPromptAccount = () => location.href = '/oauth2/v1/ely?client_id=ely&redirect_uri=http%3A%2F%2Fely.by%2Fauthorization%2Foauth&response_type=code&scope=account_info%2Caccount_email&prompt=select_account';
window.testOAuthPromptPermissions = (loginHint = '') => location.href = `/oauth2/v1/ely?client_id=ely&redirect_uri=http%3A%2F%2Fely.by%2Fauthorization%2Foauth&response_type=code&scope=account_info%2Caccount_email&prompt=consent&login_hint=${loginHint}`; window.testOAuthPromptPermissions = (loginHint = '') => location.href = `/oauth2/v1/ely?client_id=ely&redirect_uri=http%3A%2F%2Fely.by%2Fauthorization%2Foauth&response_type=code&scope=account_info%2Caccount_email&prompt=consent&login_hint=${loginHint}`;
window.testOAuthPromptAll = () => location.href = '/oauth2/v1/ely?client_id=ely&redirect_uri=http%3A%2F%2Fely.by%2Fauthorization%2Foauth&response_type=code&scope=account_info%2Caccount_email&prompt=select_account,consent'; window.testOAuthPromptAll = () => location.href = '/oauth2/v1/ely?client_id=ely&redirect_uri=http%3A%2F%2Fely.by%2Fauthorization%2Foauth&response_type=code&scope=account_info%2Caccount_email&prompt=select_account,consent';