Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### IntelliJ IDEA ###
.idea/
*.iws
*.iml
*.ipr

### VS Code ###
.vscode/

### npm install files ###
package-lock.json
node_modules/
37 changes: 0 additions & 37 deletions client/.gitignore

This file was deleted.

9 changes: 1 addition & 8 deletions client/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,2 @@
FROM ubuntu:18.04 AS clone

RUN apt update
RUN apt install -y git

RUN git clone -b lab4_js https://github.com/Winetq/spring-boot-labs.git

FROM httpd:2.4
COPY --from=clone /spring-boot-labs/. /usr/local/apache2/htdocs/
COPY . /usr/local/apache2/htdocs/
9 changes: 9 additions & 0 deletions client/Dockerfile.clone
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM ubuntu:18.04 AS clone

RUN apt update
RUN apt install -y git

RUN git clone -b lab4_js https://github.com/Winetq/spring-boot-labs.git

FROM httpd:2.4
COPY --from=clone /spring-boot-labs/. /usr/local/apache2/htdocs/
98 changes: 98 additions & 0 deletions client/auth/auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
const oktaAuth = new OktaAuth({
issuer: 'https://integrator-7447834.okta.com/oauth2/default',
clientId: '0oaw3nzfn0RvOt7cc697',
redirectUri: window.location.origin + '/index.html',
scopes: ['openid', 'profile', 'email', `offline_access`],
responseType: ['code'],
pkce: true,
tokenManager: {
storage: 'localStorage',
autoRenew: true
}
});


async function handleAuthCallback() {
if (window.location.search.includes('code=')) {
try {
await oktaAuth.handleLoginRedirect(); // exchange code for tokens
window.history.replaceState({}, document.title, '/index.html');
await showUserInfo();
} catch (e) {
console.error('Callback error:', e);
}
}
}

function redirectToLogin() {
oktaAuth.signInWithRedirect();
}

async function showUserInfo() {
const accessToken = oktaAuth.getAccessToken();
const idToken = oktaAuth.getIdToken();
const refreshToken = oktaAuth.getRefreshToken();

if (!accessToken || !idToken) return;

const userinfo = await oktaAuth.getUser();
const section = document.querySelector('.main-section');
section.innerHTML = `
<h2>Welcome ${userinfo.name} (${userinfo.email})</h2>
<button id="logoutBtn" class="ui-control ui-button">Logout</button>
<pre style="word-break: break-all; white-space: pre-wrap;">Access Token: \n${accessToken}</pre>
<pre style="word-break: break-all; white-space: pre-wrap;">ID Token: \n${idToken}</pre>
<pre style="word-break: break-all; white-space: pre-wrap;">Refresh Token: \n${refreshToken}</pre>
`;
document.getElementById('logoutBtn').onclick = logout;
showAuthenticatedNavigation();
}

function showAuthenticatedNavigation() {
const coachesNav = document.getElementById('coaches-nav');
if (coachesNav) {
coachesNav.style.display = 'inline-block';
}
}

function hideAuthenticatedNavigation() {
const coachesNav = document.getElementById('coaches-nav');
if (coachesNav) {
coachesNav.style.display = 'none';
}
}

async function logout() {
try {
oktaAuth.tokenManager.clear(); // clear tokens
hideAuthenticatedNavigation();
await oktaAuth.signOutOfOkta();
} catch (error) {
console.error('Logout error:', error);
// Even if signOut fails, clear tokens, hide and reload
oktaAuth.tokenManager.clear();
hideAuthenticatedNavigation();
window.location.reload();
}
}

function submitSigninForm(event) {
event.preventDefault();
redirectToLogin();
}

async function init() {
await handleAuthCallback();

if (await oktaAuth.isAuthenticated()) {
console.log('User is authenticated');
await showUserInfo();
} else {
console.log('User is not authenticated');
hideAuthenticatedNavigation();
const signinForm = document.getElementById('signinForm');
signinForm.addEventListener('submit', submitSigninForm);
}
}

window.addEventListener('load', init);
Loading