Skip to content

Commit

Permalink
NR-220019: App Token auth
Browse files Browse the repository at this point in the history
  • Loading branch information
cdillard-NewRelic committed Feb 6, 2024
1 parent 016aad2 commit 882f48a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 15 deletions.
6 changes: 4 additions & 2 deletions Agent/Harvester/DataStore/NRMAAgentConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,13 @@ - (void) setLoggingURL {
else {
_loggingURL = kNRMA_DEFAULT_LOGGING_HOST;
}
_loggingURL = [_loggingURL stringByAppendingFormat:@"/log/v1"];
_loggingURL = [_loggingURL stringByAppendingFormat:@"/mobile/logs"];

NSString* logURL = [NSString stringWithFormat:@"%@%@", @"https://", _loggingURL];

[NRLogger setLogURL:logURL];

[NRLogger setLogIngestKey:self.applicationToken.value];
}

+ (NRMAConnectInformation*) connectionInformation
Expand Down
2 changes: 1 addition & 1 deletion Agent/Utilities/NRLogger.m
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ - (void)upload {
NSData* formattedData = [logMessagesJson dataUsingEncoding:NSUTF8StringEncoding];
NSURLSession *session = [NSURLSession sessionWithConfiguration:NSURLSession.sharedSession.configuration];
NSMutableURLRequest* req = [NSMutableURLRequest requestWithURL:[NSURL URLWithString: self->logURL]];
[req setValue:self->logIngestKey forHTTPHeaderField:@"Api-Key"];
[req setValue:self->logIngestKey forHTTPHeaderField:@"X-App-License-Key"];

req.HTTPMethod = @"POST";
NSString* nrSessiondId = [[[NewRelicAgentInternal sharedInstance] currentSessionId] copy];
Expand Down
2 changes: 0 additions & 2 deletions Test Harness/NRTestApp/NRAPI-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
<string></string>
<key>collectorAddress</key>
<string></string>
<key>logIngestKey</key>
<string></string>
<key>logEntityGuid</key>
<string></string>
<key>NRAPIKey</key>
Expand Down
13 changes: 3 additions & 10 deletions Test Harness/NRTestApp/NRTestApp/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

NewRelic.setMaxEventPoolSize(5000)
NewRelic.setMaxEventBufferTime(60)

// REMOTE LOGGING WORKAROUND: This is required to use a New Relic Ingest Key for logging (until Mobile app token is valid for authenticating with the logs endpoint.)
// Comment out the following if else statement if log API starts accepting applicationToken as Api-Key.
if let logIngestKey = plistHelper.objectFor(key: "logIngestKey", plist: "NRAPI-Info") as? String, !logIngestKey.isEmpty {
NRLogger.setLogIngestKey(logIngestKey)
}
else {
NewRelic.logInfo("NRLogger API uploading disabled. No URL given.")
}

// REMOTE LOGGING: This is required to use a New Relic Mobile Logging.

if let logEntityGuid = plistHelper.objectFor(key: "logEntityGuid", plist: "NRAPI-Info") as? String, !logEntityGuid.isEmpty {
NRLogger.setLogEntityGuid(logEntityGuid)
}
else {
NewRelic.logInfo("NRLogger API uploading disabled. No URL given.")
NewRelic.logInfo("NRLogger API uploading disabled. No Entity Guid given.")
}

NewRelic.logVerbose("NewRelic.start was called.")
Expand Down

0 comments on commit 882f48a

Please sign in to comment.