Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authentication #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,6 @@ build/
!**/ios/**/default.pbxuser
!**/ios/**/default.perspectivev3
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages

# VSCODE related
.vscode/launch.json
30 changes: 22 additions & 8 deletions lib/src/transmission.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import 'dart:convert';

import 'package:dio/dio.dart';

const csrfProtectionHeader = 'X-Transmission-Session-Id';
const basicAuthentication = 'Authorization';
const proxyBasicAuthentication = 'Proxy-Authorization';

const methodAddTorrent = 'torrent-add';
const methodRemoveTorrent = 'torrent-remove';
Expand Down Expand Up @@ -104,15 +108,25 @@ class Transmission {
/// [proxyUrl] url use as a proxy, urls will be added at the end before request, default to null
/// [enableLog] boolean to show http logs or not
factory Transmission(
{String? baseUrl, String? proxyUrl, bool enableLog = false}) {
{String? baseUrl,
String? proxyUrl,
bool enableLog = false,
String? username,
String? password}) {
baseUrl ??= 'http://localhost:9091/transmission/rpc';
return Transmission._(
Dio(BaseOptions(
baseUrl: proxyUrl == null
? baseUrl
: proxyUrl + Uri.encodeComponent(baseUrl))),
proxyUrl != null,
enableLog);
Dio client = Dio(BaseOptions(
baseUrl: proxyUrl == null
? baseUrl
: proxyUrl + Uri.encodeComponent(baseUrl)));
if (username != null && password != null) {
String auth = base64.encode(utf8.encode('$username:$password'));
if (proxyUrl != null) {
client.options.headers[proxyBasicAuthentication] = 'Basic $auth';
} else {
client.options.headers[basicAuthentication] = 'Basic $auth';
}
}
return Transmission._(client, proxyUrl != null, enableLog);
}

/// close all connexions
Expand Down
27 changes: 18 additions & 9 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,63 +5,72 @@ packages:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
sha256: "8e36feea6de5ea69f2199f29cf42a450a855738c498b57c0b980e2d3cca9c362"
url: "https://pub.dev"
source: hosted
version: "1.2.0"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.dartlang.org"
sha256: "6d4193120997ecfd09acf0e313f13dc122b119e5eca87ef57a7d065ec9183762"
url: "https://pub.dev"
source: hosted
version: "1.15.0"
dio:
dependency: "direct main"
description:
name: dio
url: "https://pub.dartlang.org"
sha256: bf173c8bc66b776e3c2892b6ac56ac1a5ad73d21dd06d337f9fe656f63612947
url: "https://pub.dev"
source: hosted
version: "4.0.0"
http_parser:
dependency: transitive
description:
name: http_parser
url: "https://pub.dartlang.org"
sha256: e362d639ba3bc07d5a71faebb98cde68c05bfbcfbbb444b60b6f60bb67719185
url: "https://pub.dev"
source: hosted
version: "4.0.0"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
sha256: "2ad4cddff7f5cc0e2d13069f2a3f7a73ca18f66abd6f5ecf215219cdb3638edb"
url: "https://pub.dev"
source: hosted
version: "1.8.0"
source_span:
dependency: transitive
description:
name: source_span
url: "https://pub.dartlang.org"
sha256: d5f89a9e52b36240a80282b3dc0667dd36e53459717bb17b8fb102d30496606a
url: "https://pub.dev"
source: hosted
version: "1.8.1"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.dartlang.org"
sha256: dd11571b8a03f7cadcf91ec26a77e02bfbd6bbba2a512924d3116646b4198fc4
url: "https://pub.dev"
source: hosted
version: "1.1.0"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
sha256: a88162591b02c1f3a3db3af8ce1ea2b374bd75a7bb8d5e353bcfbdc79d719830
url: "https://pub.dev"
source: hosted
version: "1.2.0"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
sha256: "53bdf7e979cfbf3e28987552fd72f637e63f3c8724c9e56d9246942dc2fa36ee"
url: "https://pub.dev"
source: hosted
version: "1.3.0"
sdks:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ environment:

dependencies:
dio: '>=4.0.0 <5.0.0'


dev_dependencies: