Remove console.log debug stuff.

This commit is contained in:
J Shamsul Bahri (jibone))
2020-09-04 16:18:32 +08:00
parent 1ae5a74c3a
commit 667b42cfb7
12 changed files with 27 additions and 166 deletions
+1 -1
View File
@@ -35,7 +35,7 @@ const app = createApp({
return (
<SignInPage
{...props}
providers={['guest', 'custom', 'saml', ...providers]}
providers={['guest', 'custom', ...providers]}
/>
);
},
@@ -108,6 +108,9 @@ export type SamlApi = {
getProfile(options?: AuthRequestOptions): Promise<ProfileInfo | undefined>;
// FIXME: is this needed?
getAccessToken(options?: AuthRequestOptions): Promise<string>;
// Not sure if this is needed.
logout(): Promise<void>;
};
@@ -35,9 +35,6 @@ import {
type CreateOptions = {
apiOrigin: string;
basePath: string;
// oauthRequestApi?: OAuthRequestApi;
environment?: string;
provider?: AuthProvider & { id: string };
};
@@ -61,9 +58,6 @@ class SamlAuth implements SamlApi {
environment = 'development',
provider = DEFAULT_PROVIDER,
}: CreateOptions) {
// eslint-disable-next-line no-console
console.log('this is from SamlAuth');
const connector = new SamlAuthConnector<SamlSession>({
apiOrigin,
basePath,
@@ -87,37 +81,27 @@ class SamlAuth implements SamlApi {
sessionState$(): Observable<SessionState> {
return this.sessionManager.sessionState$();
}
// constructor(private readonly sessionManager: any) {}
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
constructor(private readonly sessionManager: SessionManager<SamlSession>) {
// eslint-disable-next-line no-console
console.log('this is the constructor');
}
constructor(private readonly sessionManager: SessionManager<SamlSession>) {}
async getBackstageIdentity(
options: AuthRequestOptions,
): Promise<BackstageIdentity | undefined> {
// eslint-disable-next-line no-console
console.log('===> Saml getBackstageIdentity()');
const session = await this.sessionManager.getSession(options);
// eslint-disable-next-line no-console
console.log('this this thish lkkdfkkfkfji');
// eslint-disable-next-line no-console
console.log(session);
return session?.backstageIdentity;
}
async getProfile(options: AuthRequestOptions = {}) {
// eslint-disable-next-line no-console
console.log('==> samlauth getprofile()');
const session = await this.sessionManager.getSession(options);
// eslint-disable-next-line no-console
console.log('+++ this is the session from getProfile()');
// eslint-disable-next-line no-console
console.log(session);
return session?.profile;
}
// FIXME: Is this needed?...
async getAccessToken(options: AuthRequestOptions) {
const session = await this.sessionManager.getSession(options);
return session?.userId ?? '';
}
async logout() {
await this.sessionManager.removeSession();
}
-4
View File
@@ -67,10 +67,6 @@ export class AppIdentity implements IdentityApi {
// This is indirectly called by the sign-in page to continue into the app.
setSignInResult(result: SignInResult) {
// eslint-disable-next-line no-console
console.log('this is from setSignInResult');
// eslint-disable-next-line no-console
console.log(result);
if (this.hasIdentity) {
return;
}
@@ -36,7 +36,8 @@ export type SamlResponse = {
backstageIdentity: BackstageIdentity;
};
export class SamlAuthConnector<SamlResponse> implements AuthConnector<SamlResponse> {
export class SamlAuthConnector<SamlResponse>
implements AuthConnector<SamlResponse> {
private readonly apiOrigin: string;
private readonly basePath: string;
private readonly environment: string | undefined;
@@ -57,35 +58,25 @@ export class SamlAuthConnector<SamlResponse> implements AuthConnector<SamlRespon
}
async createSession(): Promise<SamlResponse> {
// eslint-disable-next-line no-console
console.log('==> from SamlAuthConnector createSession');
const payload = await showLoginPopup({
url: 'http://localhost:7000/auth/saml/start', // FIXME: this should be from app.config or somewhere
url: 'http://localhost:7000/auth/saml/start', // FIXME: remove hardcoded here. should do something like buildUrl
name: 'SAML Login', // FIXME: change this to provider name? and not hardcode the name
origin: this.apiOrigin,
width: 450,
height: 730,
});
// eslint-disable-next-line no-console
console.log(payload);
return {
...payload,
id: payload.profile.email,
};
}
// TODO: do we need this for SAML?
async refreshSession(): Promise<any> {
// eslint-disable-next-line no-console
console.log('==> this is refresh session');
}
// FIXME: do we need this for SAML?
async refreshSession(): Promise<any> {}
async removeSession(): Promise<void> {
// eslint-disable-next-line no-console
console.log('this removes the session');
// FIXME: remove hardcoded url here... should do something like buildUrl
const res = await fetch('http://localhost:7000/auth/saml/logout', {
method: 'POST',
headers: {
@@ -15,10 +15,12 @@
*/
import { SessionManager, GetSessionOptions } from './types';
import { SamlAuthConnector, SamlResponse } from '../AuthConnector/SamlAuthConnector';
import {
SamlAuthConnector,
SamlResponse,
} from '../AuthConnector/SamlAuthConnector';
import { SessionStateTracker } from './SessionStateTracker';
type Options = {
connector: SamlAuthConnector<SamlResponse>;
};
@@ -27,18 +29,15 @@ export class SamlAuthSessionManager<T> implements SessionManager<T> {
private readonly connector: SamlAuthConnector<SamlResponse>;
private readonly stateTracker = new SessionStateTracker();
private currentSession: any | undefined; // FIXME: proper typing here
private currentSession: any | undefined; // FIXME: proper typing here?
constructor(options: Options) {
const { connector } = options;
this.connector = connector;
// this.helper = new SessionScopeHelper
}
async getSession(options: GetSessionOptions): Promise<T | undefined> {
// eslint-disable-next-line no-console
console.log('==> this is from SamlAuthSessionManager getSession()');
if (this.currentSession) {
return this.currentSession;
}
@@ -33,8 +33,6 @@ export class SamlAuthSessionStore<T> implements SamlAuthSessionManager<T> {
}
async getSession(options: GetSessionOptions): Promise<T | undefined> {
// eslint-disable-next-line no-console
console.log('==>> this is from SamlAuthSessionStore getSession()');
const session = this.loadSession();
if (session) {
@@ -36,11 +36,6 @@ const Component: ProviderComponent = ({ config, onResult }) => {
instantPopup: true,
});
// eslint-disable-next-line no-console
console.log('====++++++++++++++++++++++++++> handleLogin for commonProvider');
// eslint-disable-next-line no-console
console.log(identity);
const profile = await authApi.getProfile();
onResult({
userId: identity!.id,
@@ -26,7 +26,6 @@ import { SignInConfig, IdentityProviders, SignInProvider } from './types';
import { commonProvider } from './commonProvider';
import { guestProvider } from './guestProvider';
import { customProvider } from './customProvider';
import { samlProvider } from './samlProvider';
const PROVIDER_STORAGE_KEY = '@backstage/core:SignInPage:provider';
@@ -42,7 +41,6 @@ const signInProviders: { [key: string]: SignInProvider } = {
guest: guestProvider,
custom: customProvider,
common: commonProvider,
saml: samlProvider,
};
function validateIDs(id: string, providers: SignInProviderType): void {
@@ -1,92 +0,0 @@
/*
* Copyright 2020 Spotify AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React from 'react';
import { Grid, Typography, Button } from '@material-ui/core';
import { ProviderComponent, ProviderLoader, SignInProvider } from './types';
import { useApi, errorApiRef /* samlAuthApiRef */ } from '@backstage/core-api';
import { InfoCard } from '../InfoCard/InfoCard';
const Component: ProviderComponent = ({ onResult }) => {
// const samlApi = useApi(samlAuthApiRef);
const errorApi = useApi(errorApiRef);
const handleSSORedirect = () => {
// FIXME: this shoudl be from identity API or something.
window.open('http://localhost:7000/auth/saml/start');
};
const receiveMessage = (event: any) => {
// FIXME: Should use the backstage identity API and not create this session storage.
window.sessionStorage.setItem(
'helixSession',
JSON.stringify(event.data.response),
);
onResult({
userId: event.data.response.backstageIdentity,
profile: {
email: event.data.response.profile.email,
displayName: event.data.response.profile.displayName,
},
});
};
const handleLogin = async () => {
try {
// FIXME: this should be handle through backstage API or something.
handleSSORedirect();
window.addEventListener('message', receiveMessage, false);
} catch (error) {
errorApi.post(error);
}
};
return (
<Grid item>
<InfoCard
title="SAML"
actions={
<Button color="primary" variant="outlined" onClick={handleLogin}>
Sign In
</Button>
}
>
<Typography variant="body1">Sign In using SAML lolololol</Typography>
</InfoCard>
</Grid>
);
};
const loader: ProviderLoader = async () => {
// FIXME: should get the profile from identiy API not from storage session.
const sessionRaw = window.sessionStorage.getItem('helixSession');
if (!sessionRaw) {
return undefined;
}
const session = JSON.parse(sessionRaw);
return {
userId: session.backstageIdentity,
profile: {
email: session.profile.email,
displayName: session.profile.displayName,
},
};
};
export const samlProvider: SignInProvider = { Component, loader };
+4 -4
View File
@@ -36,7 +36,7 @@ export type SignInConfig = {
| ApiRef<SamlApi>;
};
export type IdentityProviders = ('guest' | 'custom' | 'saml' | SignInConfig)[];
export type IdentityProviders = ('guest' | 'custom' | SignInConfig)[];
export type ProviderComponent = ComponentType<
SignInPageProps & { config: SignInConfig }
@@ -44,9 +44,9 @@ export type ProviderComponent = ComponentType<
export type ProviderLoader = (
apis: ApiHolder,
apiRef: ApiRef<
OAuthApi & ProfileInfoApi & BackstageIdentityApi & SessionStateApi
>,
apiRef:
| ApiRef<OAuthApi & ProfileInfoApi & BackstageIdentityApi & SessionStateApi>
| ApiRef<SamlApi>,
) => Promise<SignInResult | undefined>;
export type SignInProvider = {
@@ -55,17 +55,6 @@ export class SamlAuthProvider implements AuthProviderRouteHandlers {
// for non-oauth auth flows.
// TODO: This flow doesn't issue an identity token that can be used to validate
// the identity of the user in other backends, which we need in some form.
console.log('===>');
console.log('===>');
console.log('===>');
console.log('===>');
console.log('===>');
console.log('===>');
console.log('===>');
console.log('===>');
console.log('===>');
console.log('===>');
console.log('===>');
console.log('===> SamlAuthProvider constructor');
console.log(profile);
done(undefined, {