Skip to content

Commit

Permalink
Send token as header instead of query parameter for downloads.
Browse files Browse the repository at this point in the history
Closes #972
  • Loading branch information
maniac103 committed May 4, 2020
1 parent c6bc6f6 commit 0b12dbc
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions app/src/main/java/com/gh4a/utils/UiUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,9 @@ public static Dialog createProgressDialog(Context context, @StringRes int messag

private static void enqueueDownload(Context context, Uri uri, String fileName,
String description, String mimeType, String mediaType, boolean wifiOnly) {
final String token = Gh4Application.get().getAuthToken();
final DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
DownloadManager.Request request = new DownloadManager.Request(uri)
final DownloadManager.Request request = new DownloadManager.Request(uri)
.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName)
.setDescription(description)
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
Expand All @@ -223,6 +224,9 @@ private static void enqueueDownload(Context context, Uri uri, String fileName,
if (mediaType != null) {
request.addRequestHeader("Accept", mediaType);
}
if (token != null) {
request.addRequestHeader("Authorization", "Token " + token);
}
if (mimeType != null) {
request.setMimeType(mimeType);
}
Expand Down Expand Up @@ -252,10 +256,7 @@ private static void enqueueDownload(final Context context, String url, final Str
return;
}

final Uri uri = Uri.parse(url).buildUpon()
.appendQueryParameter("access_token", Gh4Application.get().getAuthToken())
.build();

final Uri uri = Uri.parse(url);
if (!downloadNeedsWarning(context)) {
enqueueDownload(context, uri, fileName, description, mimeType, mediaType, false);
return;
Expand Down

0 comments on commit 0b12dbc

Please # to comment.