Skip to content

Commit

Permalink
remove user token after account is deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
mojganii committed Sep 12, 2023
1 parent e05cc2a commit 00cbcf6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
9 changes: 9 additions & 0 deletions ios/MullvadREST/RESTAccessTokenManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,14 @@ extension REST {

return operation
}

func invalidateToken(for accountNumber: String) {
operationQueue.addOperation(AsyncBlockOperation(dispatchQueue: dispatchQueue) { [weak self] in
guard let self else {
return
}
self.tokens.removeValue(forKey: accountNumber)
})
}
}
}
4 changes: 3 additions & 1 deletion ios/MullvadREST/RESTAccountsProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ extension REST {
retryStrategy: RetryStrategy,
completion: @escaping CompletionHandler<Void>
) -> Cancellable {
let accessTokenProvider = createAuthorizationProvider(accountNumber: accountNumber)
let requestHandler = AnyRequestHandler(createURLRequest: { endpoint, authorization in
var requestBuilder = try self.requestFactory.createRequestBuilder(
endpoint: endpoint,
Expand All @@ -104,13 +105,14 @@ extension REST {
requestBuilder.addValue(accountNumber, forHTTPHeaderField: "Mullvad-Account-Number")

return requestBuilder.getRequest()
}, authorizationProvider: createAuthorizationProvider(accountNumber: accountNumber))
}, authorizationProvider: accessTokenProvider)

let responseHandler = AnyResponseHandler { response, data -> ResponseHandlerResult<Void> in
let statusCode = HTTPStatus(rawValue: response.statusCode)

switch statusCode {
case let statusCode where statusCode.isSuccess:
accessTokenProvider.invalidateToken(for: accountNumber)
return .success(())
default:
return .unhandledResponse(
Expand Down
5 changes: 5 additions & 0 deletions ios/MullvadREST/RESTAuthorization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Operations
protocol RESTAuthorizationProvider {
func getAuthorization(completion: @escaping (Result<REST.Authorization, Swift.Error>) -> Void)
-> Cancellable
func invalidateToken(for accountNumber: String)
}

extension REST {
Expand All @@ -37,6 +38,10 @@ extension REST {
})
}
}

func invalidateToken(for accountNumber: String) {
accessTokenManager.invalidateToken(for: accountNumber)
}
}
}

Expand Down

0 comments on commit 00cbcf6

Please sign in to comment.