@@ -32,3 +32,179 @@ enum OAuthProvider {
32
32
workos,
33
33
zoom,
34
34
}
35
+
36
+ /// OAuth client grant types supported by the OAuth 2.1 server.
37
+ /// Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
38
+ enum OAuthClientGrantType {
39
+ authorizationCode ('authorization_code' ),
40
+ refreshToken ('refresh_token' );
41
+
42
+ final String value;
43
+ const OAuthClientGrantType (this .value);
44
+ }
45
+
46
+ /// OAuth client response types supported by the OAuth 2.1 server.
47
+ /// Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
48
+ enum OAuthClientResponseType {
49
+ code ('code' );
50
+
51
+ final String value;
52
+ const OAuthClientResponseType (this .value);
53
+ }
54
+
55
+ /// OAuth client type indicating whether the client can keep credentials confidential.
56
+ /// Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
57
+ enum OAuthClientType {
58
+ public ('public' ),
59
+ confidential ('confidential' );
60
+
61
+ final String value;
62
+ const OAuthClientType (this .value);
63
+
64
+ static OAuthClientType fromString (String value) {
65
+ return OAuthClientType .values.firstWhere ((e) => e.value == value);
66
+ }
67
+ }
68
+
69
+ /// OAuth client registration type.
70
+ /// Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
71
+ enum OAuthClientRegistrationType {
72
+ dynamic ('dynamic' ),
73
+ manual ('manual' );
74
+
75
+ final String value;
76
+ const OAuthClientRegistrationType (this .value);
77
+
78
+ static OAuthClientRegistrationType fromString (String value) {
79
+ return OAuthClientRegistrationType .values
80
+ .firstWhere ((e) => e.value == value);
81
+ }
82
+ }
83
+
84
+ /// OAuth client object returned from the OAuth 2.1 server.
85
+ /// Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
86
+ class OAuthClient {
87
+ /// Unique identifier for the OAuth client
88
+ final String clientId;
89
+
90
+ /// Human-readable name of the OAuth client
91
+ final String clientName;
92
+
93
+ /// Client secret (only returned on registration and regeneration)
94
+ final String ? clientSecret;
95
+
96
+ /// Type of OAuth client
97
+ final OAuthClientType clientType;
98
+
99
+ /// Token endpoint authentication method
100
+ final String tokenEndpointAuthMethod;
101
+
102
+ /// Registration type of the client
103
+ final OAuthClientRegistrationType registrationType;
104
+
105
+ /// URI of the OAuth client
106
+ final String ? clientUri;
107
+
108
+ /// Array of allowed redirect URIs
109
+ final List <String > redirectUris;
110
+
111
+ /// Array of allowed grant types
112
+ final List <OAuthClientGrantType > grantTypes;
113
+
114
+ /// Array of allowed response types
115
+ final List <OAuthClientResponseType > responseTypes;
116
+
117
+ /// Scope of the OAuth client
118
+ final String ? scope;
119
+
120
+ /// Timestamp when the client was created
121
+ final String createdAt;
122
+
123
+ /// Timestamp when the client was last updated
124
+ final String updatedAt;
125
+
126
+ OAuthClient ({
127
+ required this .clientId,
128
+ required this .clientName,
129
+ this .clientSecret,
130
+ required this .clientType,
131
+ required this .tokenEndpointAuthMethod,
132
+ required this .registrationType,
133
+ this .clientUri,
134
+ required this .redirectUris,
135
+ required this .grantTypes,
136
+ required this .responseTypes,
137
+ this .scope,
138
+ required this .createdAt,
139
+ required this .updatedAt,
140
+ });
141
+
142
+ factory OAuthClient .fromJson (Map <String , dynamic > json) {
143
+ return OAuthClient (
144
+ clientId: json['client_id' ] as String ,
145
+ clientName: json['client_name' ] as String ,
146
+ clientSecret: json['client_secret' ] as String ? ,
147
+ clientType: OAuthClientType .fromString (json['client_type' ] as String ),
148
+ tokenEndpointAuthMethod: json['token_endpoint_auth_method' ] as String ,
149
+ registrationType: OAuthClientRegistrationType .fromString (
150
+ json['registration_type' ] as String ),
151
+ clientUri: json['client_uri' ] as String ? ,
152
+ redirectUris: (json['redirect_uris' ] as List ).cast <String >(),
153
+ grantTypes: (json['grant_types' ] as List )
154
+ .map ((e) => OAuthClientGrantType .values
155
+ .firstWhere ((gt) => gt.value == e as String ))
156
+ .toList (),
157
+ responseTypes: (json['response_types' ] as List )
158
+ .map ((e) => OAuthClientResponseType .values
159
+ .firstWhere ((rt) => rt.value == e as String ))
160
+ .toList (),
161
+ scope: json['scope' ] as String ? ,
162
+ createdAt: json['created_at' ] as String ,
163
+ updatedAt: json['updated_at' ] as String ,
164
+ );
165
+ }
166
+ }
167
+
168
+ /// Parameters for creating a new OAuth client.
169
+ /// Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
170
+ class CreateOAuthClientParams {
171
+ /// Human-readable name of the OAuth client
172
+ final String clientName;
173
+
174
+ /// URI of the OAuth client
175
+ final String ? clientUri;
176
+
177
+ /// Array of allowed redirect URIs
178
+ final List <String > redirectUris;
179
+
180
+ /// Array of allowed grant types (optional, defaults to authorization_code and refresh_token)
181
+ final List <OAuthClientGrantType >? grantTypes;
182
+
183
+ /// Array of allowed response types (optional, defaults to code)
184
+ final List <OAuthClientResponseType >? responseTypes;
185
+
186
+ /// Scope of the OAuth client
187
+ final String ? scope;
188
+
189
+ CreateOAuthClientParams ({
190
+ required this .clientName,
191
+ this .clientUri,
192
+ required this .redirectUris,
193
+ this .grantTypes,
194
+ this .responseTypes,
195
+ this .scope,
196
+ });
197
+
198
+ Map <String , dynamic > toJson () {
199
+ return {
200
+ 'client_name' : clientName,
201
+ if (clientUri != null ) 'client_uri' : clientUri,
202
+ 'redirect_uris' : redirectUris,
203
+ if (grantTypes != null )
204
+ 'grant_types' : grantTypes! .map ((e) => e.value).toList (),
205
+ if (responseTypes != null )
206
+ 'response_types' : responseTypes! .map ((e) => e.value).toList (),
207
+ if (scope != null ) 'scope' : scope,
208
+ };
209
+ }
210
+ }
0 commit comments