Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

feature: add OpenShiftCluster#getOauthUrl #973

Closed
wants to merge 4 commits into from
Closed
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
5 changes: 2 additions & 3 deletions frontend/.env.docker.staging-api
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
LAUNCHER_BACKEND_URL=https://forge.api.prod-preview.openshift.io/api
LAUNCHER_CREATOR_URL=https://launch.prod-preview.openshift.io/launch/creator

LAUNCHER_KEYCLOAK_URL=https://sso.openshift.io/auth
LAUNCHER_KEYCLOAK_CLIENT_ID=openshiftio-public
LAUNCHER_KEYCLOAK_REALM=rh-developers-launch
REACT_APP_AUTHENTICATION=oauth-cluster
REACT_APP_OAUTH_OPENSHIFT_CLIENT_ID=openshift-public
3 changes: 2 additions & 1 deletion frontend/packages/launcher-app/.env.production
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
REACT_APP_CREATOR_API_URL=/launch/creator
REACT_APP_LAUNCHER_API_URL=/launch/api

REACT_APP_KEYCLOAK_CLIENT_ID=openshiftio-public
REACT_APP_AUTHENTICATION=oauth-cluster
REACT_APP_OAUTH_OPENSHIFT_CLIENT_ID=openshift-public
6 changes: 2 additions & 4 deletions frontend/packages/launcher-app/.env.production-api
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
REACT_APP_CREATOR_API_URL=https://forge.api.openshift.io/creator
REACT_APP_LAUNCHER_API_URL=https://forge.api.openshift.io/api

REACT_APP_AUTHENTICATION=keycloak
REACT_APP_KEYCLOAK_CLIENT_ID=openshiftio-public
REACT_APP_KEYCLOAK_REALM=rh-developers-launch
REACT_APP_KEYCLOAK_URL=https://sso.openshift.io/auth
REACT_APP_AUTHENTICATION=oauth-cluster
REACT_APP_OAUTH_OPENSHIFT_CLIENT_ID=openshift-public
6 changes: 2 additions & 4 deletions frontend/packages/launcher-app/.env.staging-api
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
REACT_APP_CREATOR_API_URL=https://forge.api.prod-preview.openshift.io/creator
REACT_APP_LAUNCHER_API_URL=https://forge.api.prod-preview.openshift.io/api

REACT_APP_AUTHENTICATION=keycloak
REACT_APP_KEYCLOAK_CLIENT_ID=openshiftio-public
REACT_APP_KEYCLOAK_REALM=rh-developers-launch
REACT_APP_KEYCLOAK_URL=https://sso.openshift.io/auth
REACT_APP_AUTHENTICATION=oauth-cluster
REACT_APP_OAUTH_OPENSHIFT_CLIENT_ID=openshift-public
1 change: 0 additions & 1 deletion frontend/packages/launcher-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"react-use-sessionstorage": "1.0.2",
"axios": "0.19.0",
"jssha": "2.3.1",
"keycloak-js": "6.0.1",
"query-string": "6.8.1",
"uuid": "3.3.2",
"lscache": "1.3.0",
Expand Down
22 changes: 6 additions & 16 deletions frontend/packages/launcher-app/src/app/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from 'axios';

import { OpenshiftConfig, KeycloakConfig, GitProviderConfig } from '../auth/types';
import { OpenshiftConfig, GitProviderConfig } from '../auth/types';
import { checkNotNull } from '../client/helpers/preconditions';

function getEnv(env: string | undefined, name: string): string | undefined {
Expand All @@ -18,34 +18,25 @@ function requireEnv(env: string | undefined, name: string): string {
return checkNotNull(getEnv(env, name), `process.env.${name}`);
}

function getAuthMode(keycloakUrl?: string, openshiftOAuthUrl?: string) {
function getAuthMode(openshiftOAuthUrl?: string) {
const authMode = getEnv(process.env.REACT_APP_AUTHENTICATION, 'authMode');
if (authMode) {
return authMode;
}
if (keycloakUrl) {
return 'keycloak';
}
if (openshiftOAuthUrl) {
return 'oauth-openshift'
}
return 'no';
}

function getAuthConfig(authMode: string): KeycloakConfig | OpenshiftConfig | undefined {
function getAuthConfig(authMode: string): OpenshiftConfig | undefined {
switch (authMode) {
case 'keycloak':
return {
clientId: requireEnv(process.env.REACT_APP_KEYCLOAK_CLIENT_ID, 'keycloakClientId'),
realm: requireEnv(process.env.REACT_APP_KEYCLOAK_REALM, 'keycloakRealm'),
url: requireEnv(process.env.REACT_APP_KEYCLOAK_URL, 'keycloakUrl'),
gitProvider: (getEnv(process.env.REACT_APP_GIT_PROVIDER, 'gitProvider') || 'github') === 'github' ? 'github' : 'gitea'
} as KeycloakConfig;
case 'oauth-cluster':
case 'oauth-openshift':
const base: OpenshiftConfig = {
openshift: {
clientId: requireEnv(process.env.REACT_APP_OAUTH_OPENSHIFT_CLIENT_ID, 'openshiftOAuthClientId'),
url: requireEnv(process.env.REACT_APP_OAUTH_OPENSHIFT_URL, 'openshiftOAuthUrl'),
url: getEnv(process.env.REACT_APP_OAUTH_OPENSHIFT_URL, 'openshiftOAuthUrl'),
validateTokenUri: `${requireEnv(process.env.REACT_APP_LAUNCHER_API_URL, 'launcherApiUrl')}/services/openshift/user`,
},
loadGitProvider: () => {
Expand Down Expand Up @@ -89,9 +80,8 @@ function getAuthConfig(authMode: string): KeycloakConfig | OpenshiftConfig | und

export const publicUrl = process.env.PUBLIC_URL && `${process.env.PUBLIC_URL}/`;

export const keycloakUrl = getEnv(process.env.REACT_APP_KEYCLOAK_URL, 'keycloakUrl');
export const openshiftOAuthUrl = getEnv(process.env.REACT_APP_OAUTH_OPENSHIFT_URL, 'openshiftOAuthUrl');
export const authMode = getAuthMode(keycloakUrl, openshiftOAuthUrl)
export const authMode = getAuthMode(openshiftOAuthUrl)

export const authConfig = getAuthConfig(authMode);

Expand Down
11 changes: 5 additions & 6 deletions frontend/packages/launcher-app/src/app/launcher-app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ import React from 'react';
import { Redirect, Route, Switch } from 'react-router';
import { BrowserRouter } from 'react-router-dom';
import { AuthenticationApiContext, useAuthenticationApiStateProxy } from '../auth/auth-context';
import { AuthRouter, newAuthApi } from '../auth/authentication-api-factory';
import { newAuthApi } from '../auth/authentication-api-factory';
import { createRouterLink, getRequestedRoute, useRouter } from '../router/use-router';
import { authConfig, authMode, creatorApiUrl, launcherApiUrl, publicUrl } from './config';
import './launcher-app.scss';
import { Layout } from './layout';
import { LoginPage } from './login-page';
import { LauncherMenu } from '../launcher/launcher';
import { CreateNewAppFlow } from '../flows/create-new-app-flow';
import { ImportExistingFlow } from '../flows/import-existing-flow';
import { DeployExampleAppFlow } from '../flows/deploy-example-app-flow';
import { DataLoader } from '@launcher/component';
import { LauncherDepsProvider } from '../contexts/launcher-client-provider';
import { LoginPage } from './login-page';


function Routes(props: {}) {
Expand Down Expand Up @@ -42,11 +42,12 @@ function Routes(props: {}) {
const DeployExampleAppFlowRoute = () => (<WithCancel>{onCancel => <DeployExampleAppFlow onCancel={onCancel} />}</WithCancel>);
return (
<Switch>
<Route path="/" exact component={LoginPage} />
<Route path="/home" exact component={Menu} />
<Route path="/flow/new-app" exact component={CreateNewAppFlowRoute} />
<Route path="/flow/import-existing-app" exact component={ImportExistingFlowRoute} />
<Route path="/flow/deploy-example-app" exact component={DeployExampleAppFlowRoute} />
<Redirect to="/home" />
<Redirect to="/" />
</Switch>
);
}
Expand Down Expand Up @@ -78,9 +79,7 @@ export function LauncherApp() {
creatorUrl={creatorApiUrl}
launcherUrl={launcherApiUrl}
>
<AuthRouter loginPage={LoginPage} basename={publicUrl}>
<HomePage />
</AuthRouter>
<HomePage />
</LauncherDepsProvider>
</AuthenticationApiContext.Provider>
</DataLoader >
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
$assetPath: "./assets/logo";

.main {
background-color: #fff;
margin:-20px
}

.intro {
background-image: url(#{$assetPath}/background.png);
background-size: cover;
Expand Down Expand Up @@ -76,7 +81,7 @@ button.loginButton {
button.loginButton {
font-size: 10pt;
}

.container {
margin-top: 0;
display: initial;
Expand Down
13 changes: 7 additions & 6 deletions frontend/packages/launcher-app/src/app/login-page.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import { Button, Card, CardBody, CardFooter, CardHeader, PageSection, PageSectionVariants, Text, TextContent, TextVariants } from '@patternfly/react-core';
import { ExternalLinkSquareAltIcon } from '@patternfly/react-icons';
import * as React from 'react';
import { useAuthenticationApi } from '../auth/auth-context';
import { Layout } from './layout';
import style from './login-page.module.scss';
import { NewAppRuntimesLoader } from '../loaders/new-app-runtimes-loaders';
import { PropertyValue } from '../client/types';
import { useRouter, createRouterLink } from '../router/use-router';

function LoginCard() {
const auth = useAuthenticationApi();
const router = useRouter();
const homeLink = createRouterLink(router, '/home');

return (
<div className={style.loginCard}>
<p className={style.loginText}>
When you click on start, you will first have to login or register an account for free
with the Red Hat Developer Program.
</p>
<Button variant="primary" onClick={auth.login} className={style.loginButton}>
<Button variant="primary" onClick={homeLink.onClick} className={style.loginButton}>
Start
</Button>
</div>
Expand All @@ -41,7 +42,7 @@ function Runtime(props: RuntimeProps) {
}

export const LoginPage = () => (
<Layout>
<div className={style.main}>
<section className={style.intro}>
<div className="container">
<h1 className={style.mainTitle}>Launcher</h1>
Expand Down Expand Up @@ -70,5 +71,5 @@ export const LoginPage = () => (
{runtimes => runtimes.map(r => (<Runtime {...r} key={r.id} />))}
</NewAppRuntimesLoader>
</PageSection>
</Layout>
</div>
);
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import MockAuthenticationApi from './impl/mock-authentication-api';
import { KeycloakAuthenticationApi } from './impl/keycloak-authentication-api';
import { ClusterAuthenticationApi } from './impl/cluster-authentication-api';
import NoAuthenticationApi from './impl/no-authentication-api';
import { AuthenticationApi } from './authentication-api';
import { OpenshiftAuthenticationApi } from './impl/openshift-authentication-api';
import { KeycloakConfig, OpenshiftConfig } from './types';
import { OpenshiftConfig } from './types';
import { checkNotNull } from '../client/helpers/preconditions';

export { AuthenticationApiContext, useAuthenticationApi, useAuthenticationApiStateProxy } from './auth-context';
export { AuthRouter } from './auth-router';

export function newMockAuthApi() { return new MockAuthenticationApi(); }
export function newKCAuthApi(config: KeycloakConfig) { return new KeycloakAuthenticationApi(config); }
export function newKCAuthApi(config: OpenshiftConfig) { return new ClusterAuthenticationApi(config); }
export function newOpenshiftAuthApi(config: OpenshiftConfig) { return new OpenshiftAuthenticationApi(config); }
export function newNoAuthApi() { return new NoAuthenticationApi(); }

export function newAuthApi(authenticationMode?: string, config?: OpenshiftConfig|KeycloakConfig): AuthenticationApi {
export function newAuthApi(authenticationMode?: string, config?: OpenshiftConfig): AuthenticationApi {
switch (authenticationMode) {
case 'no':
return new NoAuthenticationApi();
case 'mock':
return new MockAuthenticationApi();
case 'keycloak':
return new KeycloakAuthenticationApi(checkNotNull(config as KeycloakConfig, 'keycloakConfig'));
case 'oauth-cluster':
return new ClusterAuthenticationApi(checkNotNull(config as OpenshiftConfig, 'oauthConfig'));
case 'oauth-openshift':
return new OpenshiftAuthenticationApi(checkNotNull(config as OpenshiftConfig, 'openshiftConfig'));
default:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { OpenshiftAuthenticationApi } from './openshift-authentication-api';

export class ClusterAuthenticationApi extends OpenshiftAuthenticationApi {

public generateAuthorizationLink(provider?: string, redirect?: string): string {
if (provider !== 'github' && provider !== 'gitea') {
return provider || '';
}
return super.generateAuthorizationLink(provider, redirect);
};

}
Loading