Implementation of OAuth2 in JavaScript using CORS