| Index: lib/src/utils.dart
|
| diff --git a/lib/src/utils.dart b/lib/src/utils.dart
|
| index 734c58e2687d9706ac1181a40199dc7fee2cb433..bf260eb73a06d38c52e760fe0090c78ba839ba94 100644
|
| --- a/lib/src/utils.dart
|
| +++ b/lib/src/utils.dart
|
| @@ -4,65 +4,16 @@
|
|
|
| library oauth2.utils;
|
|
|
| +import 'dart:convert';
|
| +
|
| +import 'package:crypto/crypto.dart';
|
| +
|
| /// Adds additional query parameters to [url], overwriting the original
|
| /// parameters if a name conflict occurs.
|
| Uri addQueryParameters(Uri url, Map<String, String> parameters) => url.replace(
|
| queryParameters: new Map.from(url.queryParameters)..addAll(parameters));
|
|
|
| -/// Like [String.split], but only splits on the first occurrence of the pattern.
|
| -///
|
| -/// This will always return a list of two elements or fewer.
|
| -List<String> split1(String toSplit, String pattern) {
|
| - if (toSplit.isEmpty) return [];
|
| -
|
| - var index = toSplit.indexOf(pattern);
|
| - if (index == -1) return [toSplit];
|
| - return [toSplit.substring(0, index),
|
| - toSplit.substring(index + pattern.length)];
|
| -}
|
| -
|
| -/// A WWW-Authenticate header value, parsed as per [RFC 2617][].
|
| -///
|
| -/// [RFC 2617]: http://tools.ietf.org/html/rfc2617
|
| -class AuthenticateHeader {
|
| - final String scheme;
|
| - final Map<String, String> parameters;
|
| -
|
| - AuthenticateHeader(this.scheme, this.parameters);
|
| -
|
| - /// Parses a header string. Throws a [FormatException] if the header is
|
| - /// invalid.
|
| - factory AuthenticateHeader.parse(String header) {
|
| - var split = split1(header, ' ');
|
| - if (split.length == 0) {
|
| - throw new FormatException('Invalid WWW-Authenticate header: "$header"');
|
| - } else if (split.length == 1 || split[1].trim().isEmpty) {
|
| - return new AuthenticateHeader(split[0].toLowerCase(), {});
|
| - }
|
| - var scheme = split[0].toLowerCase();
|
| - var paramString = split[1];
|
| -
|
| - // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec2.html.
|
| - var tokenChar = r'[^\0-\x1F()<>@,;:\\"/\[\]?={} \t\x7F]';
|
| - var quotedStringChar = r'(?:[^\0-\x1F\x7F"]|\\.)';
|
| - var regexp = new RegExp('^ *($tokenChar+)="($quotedStringChar*)" *(, *)?');
|
| -
|
| - var parameters = {};
|
| - var match;
|
| - do {
|
| - match = regexp.firstMatch(paramString);
|
| - if (match == null) {
|
| - throw new FormatException('Invalid WWW-Authenticate header: "$header"');
|
| - }
|
| -
|
| - paramString = paramString.substring(match.end);
|
| - parameters[match.group(1).toLowerCase()] = match.group(2);
|
| - } while (match.group(3) != null);
|
| -
|
| - if (!paramString.trim().isEmpty) {
|
| - throw new FormatException('Invalid WWW-Authenticate header: "$header"');
|
| - }
|
| -
|
| - return new AuthenticateHeader(scheme, parameters);
|
| - }
|
| +String basicAuthHeader(String identifier, String secret) {
|
| + var userPass = Uri.encodeFull(identifier) + ":" + Uri.encodeFull(secret);
|
| + return "Basic " + CryptoUtils.bytesToBase64(ASCII.encode(userPass));
|
| }
|
|
|