import Auth from '@jetbrains/ring-ui/components/auth/auth';
import hubConfig from '@ring-ui/docs/components/hub-config';
// Example config:
// var hubConfig = {
// serverUri: 'https://hub.jetbrains.com/',
// clientId: '81a0bffb-6d0f-4a38-b93a-0a4d1e567698',
// requestCredentials: 'skip',
// redirectUri: window.location.href.split('#')[0]
// };
const log = function (title, obj) {
const titleElem = document.createElement('h3');
const jsonElem = document.createElement('div');
titleElem.innerHTML = title;
jsonElem.innerHTML = JSON.stringify(obj);
document.getElementById('example').appendChild(titleElem);
document.getElementById('example').appendChild(jsonElem);
};
(async auth => {
try {
const location = await auth.init();
log('Location to restore:', location)
const token = await auth.requestToken();
log('Token:', token);
const data = await auth.requestUser();
log('User profile data:', data);
} catch (e) {
log('error', e);
}
})(new Auth(hubConfig));
import Auth from '@jetbrains/ring-ui/components/auth/auth';
import '@jetbrains/ring-ui/components/link/link.scss';
import authService from '@jetbrains/ring-ui/components/auth-dialog-service/auth-dialog-service';
import hubConfig from '@ring-ui/docs/components/hub-config';
import LandingEntryFileName from '@jetbrains/ring-ui/components/auth/landing-entry';
async function run() {
const auth = new Auth({
...hubConfig,
windowLogin: true,
redirectUri: hubConfig.redirect_uri + LandingEntryFileName
});
auth.setAuthDialogService(authService);
await auth.init();
document.querySelector('#open-link').href = LandingEntryFileName;
document.querySelector('#force-update').addEventListener('click', () => {
auth.forceTokenUpdate();
});
document.querySelector('#log-out').addEventListener('click', () => {
auth.login();
});
}
run();