Skip to content

Commit 3825cf3

Browse files
author
Bas de Vaan
committed
format to correct line lenghts
1 parent 1ea5765 commit 3825cf3

File tree

2 files changed

+34
-16
lines changed

2 files changed

+34
-16
lines changed

lib/src/oauth_grant.dart

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,21 @@ import 'package:oauth2/oauth2.dart' as oauth;
33
abstract class OAuthGrant {
44
const OAuthGrant();
55

6-
Future<String> handle(Uri authorizationEndpoint, String identifier, String secret);
6+
Future<String> handle(
7+
Uri authorizationEndpoint, String identifier, String secret);
78
}
89

910
/// Obtains credentials using a [resource owner password grant](https://tools.ietf.org/html/rfc6749#section-1.3.3).
1011
class ResourceOwnerPasswordGrant extends OAuthGrant {
1112
final String username;
1213
final String password;
1314

14-
const ResourceOwnerPasswordGrant({required this.username, required this.password});
15+
const ResourceOwnerPasswordGrant(
16+
{required this.username, required this.password});
1517

1618
@override
17-
Future<String> handle(Uri authorizationEndpoint, String identifier, String secret) async {
19+
Future<String> handle(
20+
Uri authorizationEndpoint, String identifier, String secret) async {
1821
final client = await oauth.resourceOwnerPasswordGrant(
1922
authorizationEndpoint,
2023
username,
@@ -31,7 +34,8 @@ class ClientCredentialsGrant extends OAuthGrant {
3134
const ClientCredentialsGrant();
3235

3336
@override
34-
Future<String> handle(Uri authorizationEndpoint, String identifier, String secret) async {
37+
Future<String> handle(
38+
Uri authorizationEndpoint, String identifier, String secret) async {
3539
final client = await oauth.clientCredentialsGrant(
3640
authorizationEndpoint,
3741
identifier,
@@ -58,16 +62,19 @@ class AuthorizationCodeGrant extends OAuthGrant {
5862
final Future<Uri> Function(Uri redirectUri) listen;
5963

6064
@override
61-
Future<String> handle(Uri authorizationEndpoint, String identifier, String secret) async {
65+
Future<String> handle(
66+
Uri authorizationEndpoint, String identifier, String secret) async {
6267
final grant = oauth.AuthorizationCodeGrant(
6368
identifier,
6469
authorizationEndpoint,
6570
tokenEndpoint,
6671
);
67-
var authorizationUrl = grant.getAuthorizationUrl(redirectUrl, scopes: scopes);
72+
var authorizationUrl =
73+
grant.getAuthorizationUrl(redirectUrl, scopes: scopes);
6874
await redirect(authorizationUrl);
6975
var responseUrl = await listen(redirectUrl);
70-
oauth.Client client = await grant.handleAuthorizationResponse(responseUrl.queryParameters);
76+
oauth.Client client =
77+
await grant.handleAuthorizationResponse(responseUrl.queryParameters);
7178

7279
return client.credentials.toJson();
7380
}

test/oauth_authenticator_test.dart

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ void main() {
2323
),
2424
);
2525
final testRequest = Request('GET', Uri(host: 'test'), Uri(host: 'test'));
26-
final unauthorizedResponse = Response(http.Response('body', HttpStatus.unauthorized), 'body');
27-
final authorizedResponse = Response(http.Response('body', HttpStatus.accepted), 'body');
26+
final unauthorizedResponse =
27+
Response(http.Response('body', HttpStatus.unauthorized), 'body');
28+
final authorizedResponse =
29+
Response(http.Response('body', HttpStatus.accepted), 'body');
2830

2931
test('only refresh on unauthorized and token', () async {
3032
// arrange
@@ -34,7 +36,8 @@ void main() {
3436
final expected = {'Authorization': 'Bearer token'};
3537

3638
// act
37-
final result = await authenticator.authenticate(testRequest, unauthorizedResponse);
39+
final result =
40+
await authenticator.authenticate(testRequest, unauthorizedResponse);
3841

3942
// assert
4043
verify(mockOAuthChopper.refresh()).called(1);
@@ -48,7 +51,8 @@ void main() {
4851
final authenticator = OAuthAuthenticator(mockOAuthChopper, null);
4952

5053
// act
51-
final result = await authenticator.authenticate(testRequest, authorizedResponse);
54+
final result =
55+
await authenticator.authenticate(testRequest, authorizedResponse);
5256

5357
// assert
5458
verifyNever(mockOAuthChopper.refresh());
@@ -62,7 +66,8 @@ void main() {
6266
final authenticator = OAuthAuthenticator(mockOAuthChopper, null);
6367

6468
// act
65-
final result = await authenticator.authenticate(testRequest, unauthorizedResponse);
69+
final result =
70+
await authenticator.authenticate(testRequest, unauthorizedResponse);
6671

6772
// assert
6873
verifyNever(mockOAuthChopper.refresh());
@@ -76,7 +81,8 @@ void main() {
7681
final authenticator = OAuthAuthenticator(mockOAuthChopper, null);
7782

7883
// act
79-
final result = await authenticator.authenticate(testRequest, unauthorizedResponse);
84+
final result =
85+
await authenticator.authenticate(testRequest, unauthorizedResponse);
8086

8187
// assert
8288
verify(mockOAuthChopper.refresh()).called(1);
@@ -91,18 +97,23 @@ void main() {
9197

9298
// act
9399
// assert
94-
expect(() async => await authenticator.authenticate(testRequest, unauthorizedResponse), throwsFormatException);
100+
expect(
101+
() async =>
102+
await authenticator.authenticate(testRequest, unauthorizedResponse),
103+
throwsFormatException);
95104
});
96105

97106
test("Exception not thrown if onError is supplied", () async {
98107
// arrange
99108
FormatException? result;
100109
when(mockOAuthChopper.refresh()).thenThrow(FormatException('failed'));
101110
when(mockOAuthChopper.token).thenAnswer((_) async => testToken);
102-
final authenticator = OAuthAuthenticator(mockOAuthChopper, (e, s) => result = e as FormatException);
111+
final authenticator = OAuthAuthenticator(
112+
mockOAuthChopper, (e, s) => result = e as FormatException);
103113

104114
// act
105-
final responseResult = await authenticator.authenticate(testRequest, unauthorizedResponse);
115+
final responseResult =
116+
await authenticator.authenticate(testRequest, unauthorizedResponse);
106117

107118
// assert
108119
expect(result?.message, 'failed');

0 commit comments

Comments
 (0)