Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up console log #30

Open
wants to merge 1 commit into
base: integration
Choose a base branch
from
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
147 changes: 72 additions & 75 deletions libs/oarng/src/lib/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ const anonymousCreds: Credentials = {
};

/**
* the front-end authentication service used to retrieve identity information and to manage
* the authentication process.
* the front-end authentication service used to retrieve identity information and to manage
* the authentication process.
*
* This service allows an OAR Angular application to retrieve infomation the currently logged
* This service allows an OAR Angular application to retrieve infomation the currently logged
* in user, to log the user in if they are not already logged in, and to retrieve an authentication
* token that can be used to authenticate to other backend services.
* token that can be used to authenticate to other backend services.
*
* This abstract class allows for different implementations for different execution
* contexts. In particular, mock versions can be provided for development and testing
* This abstract class allows for different implementations for different execution
* contexts. In particular, mock versions can be provided for development and testing
* contexts.
*/
export abstract class AuthenticationService {
Expand Down Expand Up @@ -66,10 +66,10 @@ export abstract class AuthenticationService {
* return valid credentials. If valid credentials are internally cached, they are returned
* for immediate use. Otherwise, credentials are fetched via fetchCredentials().
*
* @param nologin if false (default) and the user is not logged in, an attempt ot log the
* user in will be made. This may cause the browser to be redirected
* to a login service. If this value is true, redirection will not occur; instead,
* the anonymous identity will be set as the credentials.
* @param nologin if false (default) and the user is not logged in, an attempt ot log the
* user in will be made. This may cause the browser to be redirected
* to a login service. If this value is true, redirection will not occur; instead,
* the anonymous identity will be set as the credentials.
*/
public getCredentials(nologin: boolean = false): Observable<Credentials> {
if (this.isAuthenticated())
Expand All @@ -89,26 +89,26 @@ export abstract class AuthenticationService {
* fetch valid credentials. These credentials may come from a remote authentication
* service and may trigger a user log-in process.
*
* @param nologin if false (default) and the user is not logged in, an attempt to log the
* user in will be made. This may cause the browser to be redirected
* to a login service. If this value is true, redirection will not occur; instead,
* the anonymous identity will be set as the credentials.
* @param nologin if false (default) and the user is not logged in, an attempt to log the
* user in will be made. This may cause the browser to be redirected
* to a login service. If this value is true, redirection will not occur; instead,
* the anonymous identity will be set as the credentials.
*/
public abstract fetchCredentials(nologin?: boolean): Observable<Credentials>;

/**
* redirect the browser to the authentication service, instructing it to return back to
* this application after the login process is complete.
* @param returnURL the URL to redirect the browser to after a successful login to return to
* to the application. If not provided, window.location.href will be used.
* @return boolean True if the implementation issued a browser redirect; False, otherwise.
* This allows the caller to halt operations if redirection is imminent.
* redirect the browser to the authentication service, instructing it to return back to
* this application after the login process is complete.
* @param returnURL the URL to redirect the browser to after a successful login to return to
* to the application. If not provided, window.location.href will be used.
* @return boolean True if the implementation issued a browser redirect; False, otherwise.
* This allows the caller to halt operations if redirection is imminent.
*/
public abstract loginUser(returnURL?: string): boolean;
}

/**
* configuration data describing how to access the remote authentication service assembled in a
* configuration data describing how to access the remote authentication service assembled in a
* single object.
*/
export interface AuthServiceAccessConfig {
Expand All @@ -120,17 +120,17 @@ export interface AuthServiceAccessConfig {
/**
* the base URL to redirect to when it is necessary to request that the user log in. If
* not provided, a default based on serviceEndpoint will be used. It is expected that this
* URL will require a second URL to be appended to it which represents the URL for gettting
* URL will require a second URL to be appended to it which represents the URL for gettting
* back to this application after a successful login. This typically means that the loginURL
* should include queryParameters where that last parameter is for the return URL and ends with
* an equal sign ("=").
* should include queryParameters where that last parameter is for the return URL and ends with
* an equal sign ("=").
*/
loginBaseURL?: string;

/**
* the URL that should be used to redirect the user back to the current application
* from the remote login service after a successful login. If not provided, the current
* value of window.location.href will be used.
* the URL that should be used to redirect the user back to the current application
* from the remote login service after a successful login. If not provided, the current
* value of window.location.href will be used.
*/
returnURL?: string;
}
Expand All @@ -146,42 +146,42 @@ export interface AuthConfiguration extends Configuration {
}

/**
* an implementation of the AutenticationService that caches metadata updates on the
* server via a web service.
* an implementation of the AutenticationService that caches metadata updates on the
* server via a web service.
*
* This implementation is intended for use in production.
* This implementation is intended for use in production.
*/
@Injectable({
providedIn: 'root'
})
export class OARAuthenticationService extends AuthenticationService {

/**
* create the AuthService
* create the AuthService
*/
constructor(protected httpcli: HttpClient, protected configSvc: ConfigurationService) {
super()
}

/**
* the endpoint URL for the customization web service
* the endpoint URL for the customization web service
*/
get endpoint(): string {
get endpoint(): string {
try {
return this.configSvc.getConfig<AuthConfiguration>().auth.serviceEndpoint;
} catch (ex) {
if (ex instanceof Error)
if (ex instanceof Error)
ex.message = "Incomplete auth configuration: missing 'serviceEndpoint' ("+ex.message+")";
throw ex;
}
}

/**
* the URL the remote authorization service should redirect to to restart the application
* after routing the browser user through the login service.
* after routing the browser user through the login service.
* @param returnURL the URL that the login service should redirect to after a successful login
* to return the browser to this application. If not provided, the value
* of window.location.href will be used.
* of window.location.href will be used.
*/
getLoginURL(returnURL?: string): string {
let out : string|null|undefined = null;
Expand All @@ -205,19 +205,17 @@ export class OARAuthenticationService extends AuthenticationService {
* fetch valid credentials. These credentials may come from a remote authentication
* service and may trigger a user log-in process.
*
* @param nologin if false (default) and the user is not logged in, an attempt to log the
* user in will be made. This may cause the browser to be redirected
* to a login service. If this value is true, redirection will not occur; instead,
* the anonymous identity will be set as the credentials.
* @param nologin if false (default) and the user is not logged in, an attempt to log the
* user in will be made. This may cause the browser to be redirected
* to a login service. If this value is true, redirection will not occur; instead,
* the anonymous identity will be set as the credentials.
* @param returnURL the URL that the login service should redirect to after a successful login
* to return the browser to this application. If not provided, the value
* of window.location.href will be used.
* of window.location.href will be used.
*/
public fetchCredentials(nologin: boolean = false, returnURL?: string): Observable<Credentials> {
console.log('this.endpoint', this.endpoint);
return this.fetchCredentialsFrom(this.endpoint).pipe(
switchMap((c) => {
console.log("Credentials fetched for "+c.userId);
if (!nologin && ! AuthenticationService.authenticatedCreds(c))
// this will cause the browser to redirect to login service,
// terminating this application
Expand All @@ -227,15 +225,15 @@ export class OARAuthenticationService extends AuthenticationService {
}),
catchError((e) => {
console.error("Credentials not available (status = "+e.status+")");
if (e.status && e.status == 401)
if (e.status && e.status == 401)
return this.handleUnauthenticated(!nologin, returnURL);
return this.handleFetchError(e);
})
);
}

/**
* fetch credentials for the currently logged in user from a given endpoint. This will not
* fetch credentials for the currently logged in user from a given endpoint. This will not
* attempt to log the user in.
*/
public fetchCredentialsFrom(endpoint: string): Observable<Credentials> {
Expand All @@ -245,24 +243,23 @@ export class OARAuthenticationService extends AuthenticationService {
let url = endpoint;
if (! url.endsWith('/')) url += '/';
url += "auth/_tokeninfo";
console.log("Authentication request url: ", url);

return this.httpcli.get(url).pipe(
map<any, Credentials>(messageToCredentials)
);
}

/**
* handle the case where the remote service indicates that the user is not logged in. This
* handle the case where the remote service indicates that the user is not logged in. This
* implementation will redirect the browser to the login site (via loginUser()) if requested;
* otherwise, it returns anonymous credentials.
* @param authReturnURL if provided, the login process will be initiated; if this requires
* browser redirection, this parameter will be interpreeted as the
* @param authReturnURL if provided, the login process will be initiated; if this requires
* browser redirection, this parameter will be interpreeted as the
* URL to return to after completing the process.
* @return Observable<Credentials>
* @return Observable<Credentials>
*/
handleUnauthenticated(dologin: boolean, authReturnURL?: string) : Observable<Credentials> {
if (dologin)
if (dologin)
// this will cause the browser to redirect to login service,
// terminating this application
if (this.loginUser(authReturnURL))
Expand All @@ -271,20 +268,20 @@ export class OARAuthenticationService extends AuthenticationService {
}

/**
* Handle the possible errors while fetching Credentials. The error could be
* Handle the possible errors while fetching Credentials. The error could be
* directly from the HTTP call (and is, thus, an HttpErrorResponse) or an error
* occuring while processing the response (making it a simple Error). This
* implementation will interpret the type of error to report a helpful error message
* implementation will interpret the type of error to report a helpful error message
* to the consult, and then reraise the error.
* @param error The error object.
* @returns an Observable returned by throwError()
*/
handleFetchError(error: any) {
if (error.status != undefined) {
let message = null;
if (error.status == 0)
if (error.status == 0)
message = "Authentication Client/Communiction Error: " + error.error
else if (error.status >= 400 && error.status < 500)
else if (error.status >= 400 && error.status < 500)
message = "Authentication service reports: " + error.message +
"; incorrect service endpoint configuration?"
else if (error.status > 500)
Expand All @@ -293,21 +290,21 @@ export class OARAuthenticationService extends AuthenticationService {
message = "Unexpected Authentication service response: " + error.message
console.error(message);
}
else
else
console.error("Failure processing Authentication service response: "+error);

return throwError(error);
}

/**
* redirect the browser to the authentication service, instructing it to return back to
* the current landing page.
*
* redirect the browser to the authentication service, instructing it to return back to
* the current landing page.
*
* @param returnURL the URL that the login service should redirect to after a successful login
* to return the browser to this application. If not provided, the value
* of window.location.href will be used.
* @return boolean True if the implementation issued a browser redirect; False, otherwise.
* This allows the caller to halt operations if redirection is imminent.
* of window.location.href will be used.
* @return boolean True if the implementation issued a browser redirect; False, otherwise.
* This allows the caller to halt operations if redirection is imminent.
*/
public loginUser(returnURL?: string): boolean {
let loginURL = this.getLoginURL(returnURL);
Expand All @@ -318,11 +315,11 @@ export class OARAuthenticationService extends AuthenticationService {
}

/**
* An AuthService intended for development and testing purposes which simulates interaction
* with a authorization service.
* An AuthService intended for development and testing purposes which simulates interaction
* with a authorization service.
*
* This implementation does not contact any remote service. Instead, this service is provided
* with the user identity information representing the authenticated user at construction time.
* This implementation does not contact any remote service. Instead, this service is provided
* with the user identity information representing the authenticated user at construction time.
*/
@Injectable({
providedIn: 'root'
Expand All @@ -347,22 +344,22 @@ export class MockAuthenticationService extends AuthenticationService {
}

/**
* fetch valid credentials.
* fetch valid credentials.
*
* This implementation just returns the fake credentials set at construction time
*
* @param nologin if false (default) and the user is not logged in, an attempt to log the
* user in will be made. This may cause the browser to be redirected
* to a login service. If this value is true, redirection will not occur; instead,
* the anonymous identity will be set as the credentials.
* @param nologin if false (default) and the user is not logged in, an attempt to log the
* user in will be made. This may cause the browser to be redirected
* to a login service. If this value is true, redirection will not occur; instead,
* the anonymous identity will be set as the credentials.
*/
public fetchCredentials(nologin: boolean = false): Observable<Credentials> {
return of(this._fakeCred);
}

/**
* redirect the browser to the authentication service, instructing it to return back to
* this application after the login process is complete.
* redirect the browser to the authentication service, instructing it to return back to
* this application after the login process is complete.
*
* This implementation does nothing.
*/
Expand Down
5 changes: 2 additions & 3 deletions libs/oarng/src/lib/wizard/pushingsidebar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { state, style, trigger, transition, animate } from '@angular/animations'

/**
* A Panel that includes a sidebar that can be opened and closed. When it is opened,
* it pushes content out of the way (as opposed to covering over it).
* it pushes content out of the way (as opposed to covering over it).
*/
@Component({
selector: 'oar-pushing-sidebar',
Expand Down Expand Up @@ -44,12 +44,11 @@ export class PushingSidebarComponent {
constructor(private chref: ChangeDetectorRef) { }

/**
* toggle whether the sidebar is visible. When this is called, a change in
* toggle whether the sidebar is visible. When this is called, a change in
* in the visiblity of the sidebar will be animated (either opened or closed).
*/
toggleSbarView() {
this._sbarvisible = ! this._sbarvisible;
console.log("toggling view: " + this._sbarvisible);
this.chref.detectChanges();
}

Expand Down
7 changes: 3 additions & 4 deletions libs/oarng/src/lib/wizard/slideoutcol.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { state, style, trigger, transition, animate } from '@angular/animations'

/**
* A Panel that includes a sidebar that can be opened and closed. When it is opened,
* it pushes content out of the way (as opposed to covering over it).
* it pushes content out of the way (as opposed to covering over it).
*/
@Component({
selector: 'oar-slideout-col',
Expand Down Expand Up @@ -54,12 +54,11 @@ A 201 response MAY contain an ETag response header field indicating the current
]})
export class SlideoutColumnComponent {
private _helpvisible : boolean = false;

constructor(private chref: ChangeDetectorRef) { }

toggleHelpView() {
this._helpvisible = ! this._helpvisible;
console.log("toggling view: " + this._helpvisible);
this.chref.detectChanges();
}

Expand Down