1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-21 16:18:28 +01:00

Getting the user's access token for file upload (#8877)

This commit is contained in:
Tom 2024-04-23 11:26:31 -04:00 committed by GitHub
parent 38ea110755
commit 5f3844aa38
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 4 deletions

View File

@ -103,6 +103,7 @@ import { EventResponse } from "../models/response/event.response";
import { ListResponse } from "../models/response/list.response";
import { ProfileResponse } from "../models/response/profile.response";
import { UserKeyResponse } from "../models/response/user-key.response";
import { UserId } from "../types/guid";
import { AttachmentRequest } from "../vault/models/request/attachment.request";
import { CipherBulkDeleteRequest } from "../vault/models/request/cipher-bulk-delete.request";
import { CipherBulkMoveRequest } from "../vault/models/request/cipher-bulk-move.request";
@ -451,7 +452,13 @@ export abstract class ApiService {
end: string,
token: string,
) => Promise<ListResponse<EventResponse>>;
postEventsCollect: (request: EventRequest[]) => Promise<any>;
/**
* Posts events for a user
* @param request The array of events to upload
* @param userId The optional user id the events belong to. If no user id is provided the active user id is used.
*/
postEventsCollect: (request: EventRequest[], userId?: UserId) => Promise<any>;
deleteSsoUser: (organizationId: string) => Promise<void>;
getSsoUserIdentifier: () => Promise<string>;

View File

@ -118,6 +118,7 @@ import { EnvironmentService } from "../platform/abstractions/environment.service
import { PlatformUtilsService } from "../platform/abstractions/platform-utils.service";
import { StateService } from "../platform/abstractions/state.service";
import { Utils } from "../platform/misc/utils";
import { UserId } from "../types/guid";
import { AttachmentRequest } from "../vault/models/request/attachment.request";
import { CipherBulkDeleteRequest } from "../vault/models/request/cipher-bulk-delete.request";
import { CipherBulkMoveRequest } from "../vault/models/request/cipher-bulk-move.request";
@ -1423,8 +1424,8 @@ export class ApiService implements ApiServiceAbstraction {
return new ListResponse(r, EventResponse);
}
async postEventsCollect(request: EventRequest[]): Promise<any> {
const authHeader = await this.getActiveBearerToken();
async postEventsCollect(request: EventRequest[], userId?: UserId): Promise<any> {
const authHeader = await this.tokenService.getAccessToken(userId);
const headers = new Headers({
"Device-Type": this.deviceType,
Authorization: "Bearer " + authHeader,

View File

@ -70,7 +70,7 @@ export class EventUploadService implements EventUploadServiceAbstraction {
return req;
});
try {
await this.apiService.postEventsCollect(request);
await this.apiService.postEventsCollect(request, userId);
} catch (e) {
this.logService.error(e);
// Add the events back to state if there was an error and they were not uploaded.