[iOS] send access token only to catalog

This commit is contained in:
Aleksey Belouosv 2018-12-14 12:01:43 +03:00 committed by Aleksey Belousov
parent b21bf4e8c0
commit ee6d75b25c
3 changed files with 18 additions and 4 deletions

View file

@ -113,6 +113,10 @@ final class CatalogWebViewController: WebViewController {
handlePendingTransactions { decisionHandler($0) }
}
override func shouldAddAccessToken() -> Bool {
return true
}
override func webView(_ webView: WKWebView,
decidePolicyFor navigationAction: WKNavigationAction,
decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {

View file

@ -19,6 +19,7 @@ NS_ASSUME_NONNULL_BEGIN
onSuccessAuth:(MWMStringBlock _Nullable)success
onFailure:(MWMVoidBlock _Nullable)failure;
- (void)willLoadUrl:(MWMBoolBlock)decisionHandler;
- (BOOL)shouldAddAccessToken;
- (void)forward;
- (void)back;

View file

@ -100,19 +100,28 @@
{
auto request = [NSMutableURLRequest requestWithURL:self.m_url];
[request setValue:@(GetPlatform().GetAppUserAgent().Get().c_str()) forHTTPHeaderField:@"User-Agent"];
auto authHeader = [NSString stringWithFormat:@"Bearer %@",
@(GetFramework().GetUser().GetAccessToken().c_str())];
[request setValue:authHeader forHTTPHeaderField:@"Authorization"];
if (self.shouldAddAccessToken)
{
auto authHeader = [NSString stringWithFormat:@"Bearer %@",
@(GetFramework().GetUser().GetAccessToken().c_str())];
[request setValue:authHeader forHTTPHeaderField:@"Authorization"];
}
[self.webView loadRequest:request];
}
}
}];
}
- (void)willLoadUrl:(MWMBoolBlock)decisionHandler {
- (void)willLoadUrl:(MWMBoolBlock)decisionHandler
{
decisionHandler(YES);
}
- (BOOL)shouldAddAccessToken
{
return NO;
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];