import Auth from '@jetbrains/ring-ui/components/auth/auth';
import authDialogService from '@jetbrains/ring-ui/components/auth-dialog-service/auth-dialog-service';
import hubConfig from '@ring-ui/docs/components/hub-config';
import '@jetbrains/ring-ui/components/link/link__legacy.css';
// 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('b');
const jsonElem = document.createElement('span');
const lineBreak = document.createElement('br');
lineBreak.style.lineHeight = '32px';
titleElem.innerHTML = title + ' ';
jsonElem.innerHTML = JSON.stringify(obj) + '\n';
document.getElementById('example').appendChild(titleElem);
document.getElementById('example').appendChild(jsonElem);
document.getElementById('example').appendChild(lineBreak);
};
const auth = new Auth(hubConfig);
auth.setAuthDialogService(authDialogService);
(async () => {
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);
}
const forceUpdateLink = document.querySelector('#force-update');
forceUpdateLink.hidden = false;
forceUpdateLink.addEventListener('click', async () => {
const newToken = await auth.forceTokenUpdate();
log('Token has been refreshed:', newToken);
});
})();
import Auth from '@jetbrains/ring-ui/components/auth/auth';
import IFrameFlow from '@jetbrains/ring-ui/components/auth/iframe-flow'
import authDialogService from '@jetbrains/ring-ui/components/auth-dialog-service/auth-dialog-service';
import hubConfig from '@ring-ui/docs/components/hub-config';
import '@jetbrains/ring-ui/components/link/link__legacy.css';
const auth = new Auth({
...hubConfig,
EmbeddedLoginFlow: IFrameFlow
});
auth.setAuthDialogService(authDialogService);
(async () => {
try {
const location = await auth.init();
await auth.login();
const data = await auth.requestUser();
document.getElementById('example').innerHTML = JSON.stringify(data);
} catch (e) {
console.error('Failed', e);
}
})();
import Auth from '@jetbrains/ring-ui/components/auth/auth';
import '@jetbrains/ring-ui/components/link/link__legacy.css';
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';
const log = function (title, obj) {
const titleElem = document.createElement('b');
const jsonElem = document.createElement('span');
const lineBreak = document.createElement('br');
lineBreak.style.lineHeight = '32px';
titleElem.innerHTML = title + ' ';
jsonElem.innerHTML = JSON.stringify(obj) + '\n';
document.getElementById('example').appendChild(titleElem);
document.getElementById('example').appendChild(jsonElem);
document.getElementById('example').appendChild(lineBreak);
};
async function run() {
const auth = new Auth({
...hubConfig,
redirectUri: hubConfig.redirectUri + LandingEntryFileName
});
auth.setAuthDialogService(authService);
await auth.init();
const user = await auth.requestUser();
log('Logged in as:', user.name)
document.querySelector('#open-link').href = LandingEntryFileName;
document.querySelector('#force-update').addEventListener('click', async () => {
const newToken = await auth.forceTokenUpdate();
log('New token:', newToken);
});
document.querySelector('#log-out').addEventListener('click', () => {
auth.login();
});
}
run();