Fixed oauth2 analysis warnings

This commit is contained in:
thomashii@dukefirehawk.com 2022-08-27 15:52:28 +08:00
parent 3fe1778c27
commit 45218176c7
6 changed files with 9 additions and 11 deletions

View file

@ -6,7 +6,7 @@ import 'package:angel3_oauth2/angel3_oauth2.dart';
void main() async { void main() async {
var app = Angel(); var app = Angel();
var oauth2 = _ExampleAuthorizationServer(); var oauth2 = _ExampleAuthorizationServer();
var _rgxBearer = RegExp(r'^[Bb]earer ([^\n\s]+)$'); var rgxBearer = RegExp(r'^[Bb]earer ([^\n\s]+)$');
app.group('/auth', (router) { app.group('/auth', (router) {
router router
@ -17,7 +17,7 @@ void main() async {
// Assume that all other requests must be authenticated... // Assume that all other requests must be authenticated...
app.fallback((req, res) { app.fallback((req, res) {
var authToken = var authToken =
req.headers!.value('authorization')?.replaceAll(_rgxBearer, '').trim(); req.headers!.value('authorization')?.replaceAll(rgxBearer, '').trim();
if (authToken == null) { if (authToken == null) {
throw AngelHttpException.forbidden(); throw AngelHttpException.forbidden();

View file

@ -234,7 +234,7 @@ abstract class AuthorizationServer<Client, User> {
if (buf.isNotEmpty) buf.write('&'); if (buf.isNotEmpty) buf.write('&');
return buf return buf
..write( ..write(
'$k=' + Uri.encodeComponent(queryParameters[k]!), '$k=${Uri.encodeComponent(queryParameters[k]!)}',
); );
}).toString(); }).toString();

View file

@ -100,7 +100,7 @@ void main() {
var authCode = json.decode(response.body)['code'].toString(); var authCode = json.decode(response.body)['code'].toString();
var client = await grant.handleAuthorizationCode(authCode); var client = await grant.handleAuthorizationCode(authCode);
expect(client.credentials.accessToken, authCode + '_access'); expect(client.credentials.accessToken, '${authCode}_access');
}); });
test('can send refresh token', () async { test('can send refresh token', () async {
@ -111,9 +111,9 @@ void main() {
var authCode = json.decode(response.body)['code'].toString(); var authCode = json.decode(response.body)['code'].toString();
var client = await grant.handleAuthorizationCode(authCode); var client = await grant.handleAuthorizationCode(authCode);
expect(client.credentials.accessToken, authCode + '_access'); expect(client.credentials.accessToken, '${authCode}_access');
expect(client.credentials.canRefresh, isTrue); expect(client.credentials.canRefresh, isTrue);
expect(client.credentials.refreshToken, authCode + '_refresh'); expect(client.credentials.refreshToken, '${authCode}_refresh');
}); });
}); });
} }

View file

@ -32,7 +32,7 @@ void main() {
var response = await client.post( var response = await client.post(
Uri.parse('oauth2/token'), Uri.parse('oauth2/token'),
headers: { headers: {
'Authorization': 'Basic ' + base64Url.encode('foo:bar'.codeUnits), 'Authorization': 'Basic ${base64Url.encode('foo:bar'.codeUnits)}',
}, },
body: { body: {
'grant_type': 'client_credentials', 'grant_type': 'client_credentials',
@ -60,7 +60,7 @@ void main() {
var response = await client.post( var response = await client.post(
Uri.parse('/oauth2/token'), Uri.parse('/oauth2/token'),
headers: { headers: {
'Authorization': 'Basic ' + base64Url.encode('fooa:bar'.codeUnits), 'Authorization': 'Basic ${base64Url.encode('fooa:bar'.codeUnits)}',
}, },
body: { body: {
'grant_type': 'client_credentials', 'grant_type': 'client_credentials',
@ -75,7 +75,7 @@ void main() {
var response = await client.post( var response = await client.post(
Uri.parse('/oauth2/token'), Uri.parse('/oauth2/token'),
headers: { headers: {
'Authorization': 'Basic ' + base64Url.encode('foo:bara'.codeUnits), 'Authorization': 'Basic ${base64Url.encode('foo:bara'.codeUnits)}',
}, },
body: { body: {
'grant_type': 'client_credentials', 'grant_type': 'client_credentials',

View file

@ -2,7 +2,6 @@ import 'dart:async';
import 'package:angel3_framework/angel3_framework.dart'; import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel3_test/angel3_test.dart'; import 'package:angel3_test/angel3_test.dart';
import 'package:angel3_oauth2/angel3_oauth2.dart'; import 'package:angel3_oauth2/angel3_oauth2.dart';
import 'package:angel3_validate/angel3_validate.dart';
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
import 'common.dart'; import 'common.dart';

View file

@ -2,7 +2,6 @@ import 'dart:async';
import 'package:angel3_framework/angel3_framework.dart'; import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel3_test/angel3_test.dart'; import 'package:angel3_test/angel3_test.dart';
import 'package:angel3_oauth2/angel3_oauth2.dart'; import 'package:angel3_oauth2/angel3_oauth2.dart';
import 'package:angel3_validate/angel3_validate.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
import 'common.dart'; import 'common.dart';