Discover our step-by-step guide to seamlessly integrating Lovable with Okta. Learn how to secure and streamline access management in minutes.
Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
okta-config.ts
.okta-config.ts
to define your Okta settings. Replace YOUROKTACLIENTID
and YOUROKTA_DOMAIN
with your actual Okta details:
// okta-config.ts
export const oktaConfig = {
clientId: 'YOUROKTACLIENT_ID',
issuer: 'https://YOUROKTADOMAIN/oauth2/default',
redirectUri: window.location.origin + '/login/callback',
scopes: ['openid', 'profile', 'email']
};
okta-auth.service.ts
in your source directory.
import { oktaConfig } from './okta-config';
declare const OktaAuth: any;
export class OktaAuthService {
private oktaAuth: any;
constructor() {
this.oktaAuth = new OktaAuth({
clientId: oktaConfig.clientId,
issuer: oktaConfig.issuer,
redirectUri: oktaConfig.redirectUri,
scopes: oktaConfig.scopes
});
}
async signIn(username: string, password: string): Promise {
try {
const transaction = await this.oktaAuth.signIn({ username, password });
if (transaction.status === 'SUCCESS') {
// Tokens can be stored or further actions done here
return transaction;
}
} catch (err) {
console.error('Sign in failed', err);
throw err;
}
}
async isAuthenticated(): Promise {
return await this.oktaAuth.isAuthenticated();
}
async signOut(): Promise {
await this.oktaAuth.signOut();
}
}
app.ts
).loginBtn
and input fields with the IDs username
and password
:
import { OktaAuthService } from './okta-auth.service';
const authService = new OktaAuthService();
// Example: Adding a click event listener to the login button
const loginButton = document.getElementById('loginBtn');
if (loginButton) {
loginButton.addEventListener('click', async () => {
const usernameInput = (document.getElementById('username') as HTMLInputElement).value;
const passwordInput = (document.getElementById('password') as HTMLInputElement).value;
try {
const result = await authService.signIn(usernameInput, passwordInput);
alert('Login Successful!');
// Redirect or update your UI as needed
} catch (error) {
alert('Login Failed: ' + error.message);
}
});
}
okta-config.ts
and okta-auth.service.ts
) are saved in your project’s source directory.When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.