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

Keycloak Auth2/OIDC #4247

Open
wants to merge 22 commits into
base: feature/keycloak-oidc
Choose a base branch
from
Open

Conversation

boehlke
Copy link
Contributor

@boehlke boehlke commented Oct 11, 2024

No description provided.

@bastianjoel bastianjoel self-requested a review October 11, 2024 09:22
@bastianjoel bastianjoel self-assigned this Oct 11, 2024
Copy link
Member

@bastianjoel bastianjoel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in one of the CRs please revert 3b1391e.

This review does not include the worker part as I would like to see the tests passing before I have a look at it. Passing the "build-and-test-dev-image" pipeline is a hard requirement before merging to feature branches.

Besides from that please fix the linter issues. You can use npm run cleanup to do this. After reverting 3b1391e this should work without manual intervention.

public async sendMessage<T extends WorkerMessageContent>(receiver: string, msg: T): Promise<void> {
public async sendMessage<C extends WorkerMessageContent, T extends WorkerMessage<C>>(msg: T): Promise<void> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove the receiver parameter? This adds redundancy because the parameter is mandatory anyway and we now always need to specify it in the request.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

T is now to message type, not only the content type.
So msg contains the receiver. This improves type safety when using the method...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see how this improves type safety. Yes, you are not able to send messages to a wrong receiver with this but I think as the message type normally contains the receiver name it is normally quite clear which receiver to send it to.

Even if we want to do something like this I think there are much better ways to achieve something like this by for example extending the shared worker service or providing methods to generate such messages.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Yes, you are not able to send messages to a wrong receiver" ... that is how type safety is improved, and I think you strengthen my point when write, that it's "...normally quite clear...". The compiler can enforce clearity.

This solution is not ideal, but an improvement, I think. Let's discuss a better solution.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO the added redundancy overweights. I would prefer not doing this in this PR.

Comment on lines +226 to +250

public async getBlobUrl(url: string): Promise<string | null> {
await this.authTokenService.waitForValidToken();
try {
if (this.blobCache.has(url)) {
return this.blobCache.get(url);
}

// Fetch the resource as a blob
const response = await fetch(url, { headers: { Authentication: `Bearer ${this.authTokenService.rawAccessToken}` } });
if (!response.ok) {
throw new Error('Network response was not ok');
}
const blob = await response.blob();

// Create a blob URL and cache it
const blobUrl = URL.createObjectURL(blob);
this.blobCache.set(url, blobUrl);

return blobUrl;
} catch (error) {
console.error('Error loading image:', error);
return null;
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unnecessary. We are using cache control headers for mediafiles. See #1915 for further details.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main perpose is getting the blob as an object URL. The fetch call might return a cached file but still response.blob() will create a new in-memory representation of the file.

Copy link
Member

@bastianjoel bastianjoel Oct 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said.

TLDR; We had this. With cache control headers you can achieve something like this with native browser apis. This behavior is disabled in dev setup.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep it simple. Just use this.authTokenService.rawAccessToken instead of the observable. There is no benefit in keeping track of token changes here.

public constructor(private authTokenService: AuthTokenService) {
this.authTokenService.accessTokenObservable.subscribe(token => {
if (token) {
console.log(`Access token: ${token.rawAccessToken}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
console.log(`Access token: ${token.rawAccessToken}`);

client/src/app/site/services/openslides-router.service.ts Outdated Show resolved Hide resolved
@@ -63,9 +63,6 @@ export class OpenSlidesRouterService {
private updateService: UpdateService,
private operator: OperatorService
) {
_auth.logoutObservable.subscribe(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also remove from constructor when unused.

@@ -25,19 +25,15 @@ export class OpenSlidesService {
* {@method afterLoginBootup}. If not, redirect the user to the login page.
*/
public async bootup(): Promise<void> {
const online = await this.authService.doWhoAmIRequest();
const online = await this.authService.checkOnline();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly this now always does a request to a health endpoint on bootup. I think that would be unnecessary.

@@ -7,7 +7,7 @@ import { SiteWrapperComponent } from './modules/site-wrapper/components/site-wra

const routes: Routes = [
{
path: `login`,
path: `idp`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to add a redirect if we really want to change this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to a definitions folder and rename to auth.ts. Same for the other interfaces in this folder.

@bastianjoel bastianjoel assigned boehlke and unassigned bastianjoel Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants