Skip to content

Commit e4e179b

Browse files
author
Gavin Roberts
committed
Add Authorization header for V1 Services as well
1 parent 19f1fd5 commit e4e179b

File tree

1 file changed

+4
-22
lines changed

1 file changed

+4
-22
lines changed

AtlassianCloudBackupsLibrary/BackupAtlassianService.cs

+4-22
Original file line numberDiff line numberDiff line change
@@ -159,32 +159,14 @@ public async Task<IBackupJob> Execute(bool runCleanUpOnly = false)
159159
Client.DefaultRequestHeaders.Accept.Clear();
160160
Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
161161

162-
Logger.Current.Log(_logLabel, "Attempting to log in to Atlassian...");
163-
// Get auth token from the cloud instance
164-
var content =
165-
new StringContent(
166-
"{" + string.Format(" \"username\" : \"{0}\", \"password\" : \"{1}\" ", UserName,
167-
Password) + "}", Encoding.UTF8, "application/json");
168-
169-
var response = await Client.PostAsync(_service.AuthUrl, content);
170-
171-
if (response.IsSuccessStatusCode)
172-
{
173-
Logger.Current.Log(_logLabel,
174-
string.Format("Successfully logged in to the {0} account as {1}.", Account, UserName));
175-
}
176-
else
177-
{
178-
Logger.Current.Log(_logLabel, "Failed to authenticate to Atlassian cloud servers!");
179-
Logger.Current.Log(_logLabel,
180-
string.Format("Aborting backup job for {0}!", GetServiceToBeBackedUpLabel()));
181-
return this;
182-
}
162+
var basicHeaderValue = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{UserName}:{Password}"));
163+
Client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", basicHeaderValue);
183164

184165
Logger.Current.Log(_logLabel, "Triggering backup...");
185166
// Trigger backup
186167
var triggerContent =
187-
new StringContent("{ \"cbAttachments\" : true }", Encoding.UTF8, "application/json");
168+
new StringContent("{ \"cbAttachments\" : \"true\", \"exportToCloud\" : \"true\" }",
169+
Encoding.UTF8, "application/json");
188170
var triggerResponse = await Client.PostAsync(_service.BackupTriggerUrl, triggerContent);
189171

190172
if (!triggerResponse.IsSuccessStatusCode)

0 commit comments

Comments
 (0)