1
+ import 'package:http/http.dart' as http;
1
2
import 'package:oauth2/oauth2.dart' as oauth;
2
3
3
4
abstract class OAuthGrant {
4
5
const OAuthGrant ();
5
6
6
7
Future <String > handle (
7
- Uri authorizationEndpoint, String identifier, String secret);
8
+ Uri authorizationEndpoint,
9
+ String identifier,
10
+ String secret,
11
+ http.Client ? httpClient,
12
+ );
8
13
}
9
14
10
15
/// Obtains credentials using a [resource owner password grant] (https://tools.ietf.org/html/rfc6749#section-1.3.3).
11
16
class ResourceOwnerPasswordGrant extends OAuthGrant {
12
17
final String username;
13
18
final String password;
14
19
15
- const ResourceOwnerPasswordGrant (
16
- {required this .username, required this .password});
20
+ const ResourceOwnerPasswordGrant ({required this .username, required this .password});
17
21
18
22
@override
19
23
Future <String > handle (
20
- Uri authorizationEndpoint, String identifier, String secret) async {
24
+ Uri authorizationEndpoint,
25
+ String identifier,
26
+ String secret,
27
+ http.Client ? httpClient,
28
+ ) async {
21
29
final client = await oauth.resourceOwnerPasswordGrant (
22
30
authorizationEndpoint,
23
31
username,
24
32
password,
25
33
secret: secret,
26
34
identifier: identifier,
35
+ httpClient: httpClient,
27
36
);
28
37
return client.credentials.toJson ();
29
38
}
@@ -35,11 +44,16 @@ class ClientCredentialsGrant extends OAuthGrant {
35
44
36
45
@override
37
46
Future <String > handle (
38
- Uri authorizationEndpoint, String identifier, String secret) async {
47
+ Uri authorizationEndpoint,
48
+ String identifier,
49
+ String secret,
50
+ http.Client ? httpClient,
51
+ ) async {
39
52
final client = await oauth.clientCredentialsGrant (
40
53
authorizationEndpoint,
41
54
identifier,
42
55
secret,
56
+ httpClient: httpClient,
43
57
);
44
58
return client.credentials.toJson ();
45
59
}
@@ -63,18 +77,21 @@ class AuthorizationCodeGrant extends OAuthGrant {
63
77
64
78
@override
65
79
Future <String > handle (
66
- Uri authorizationEndpoint, String identifier, String secret) async {
80
+ Uri authorizationEndpoint,
81
+ String identifier,
82
+ String secret,
83
+ http.Client ? httpClient,
84
+ ) async {
67
85
final grant = oauth.AuthorizationCodeGrant (
68
86
identifier,
69
87
authorizationEndpoint,
70
88
tokenEndpoint,
89
+ httpClient: httpClient,
71
90
);
72
- var authorizationUrl =
73
- grant.getAuthorizationUrl (redirectUrl, scopes: scopes);
91
+ var authorizationUrl = grant.getAuthorizationUrl (redirectUrl, scopes: scopes);
74
92
await redirect (authorizationUrl);
75
93
var responseUrl = await listen (redirectUrl);
76
- oauth.Client client =
77
- await grant.handleAuthorizationResponse (responseUrl.queryParameters);
94
+ oauth.Client client = await grant.handleAuthorizationResponse (responseUrl.queryParameters);
78
95
79
96
return client.credentials.toJson ();
80
97
}
0 commit comments