Skip to content

Commit

Permalink
Added support for [customPostAuthPage] (#561)
Browse files Browse the repository at this point in the history
  • Loading branch information
krll-kov authored Apr 2, 2024
1 parent 285ab46 commit 1631558
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
3 changes: 3 additions & 0 deletions googleapis_auth/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.6.0
- Added support for custom post-auth html page

## 1.5.1

- `auth_browser.dart`: handle pop-up closed errors correctly.
Expand Down
11 changes: 11 additions & 0 deletions googleapis_auth/lib/auth_io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,19 @@ Future<AutoRefreshingAuthClient> clientViaApplicationDefaultCredentials({
/// {@macro googleapis_auth_close_the_client}
/// {@macro googleapis_auth_not_close_the_baseClient}
/// {@macro googleapis_auth_listen_port}
///
/// {@template googleapis_auth_custom_post_auth_page}
/// If provided, default post authentication page is replaced with html code
/// specified in [customPostAuthPage] variable.
/// {@endtemplate}
Future<AutoRefreshingAuthClient> clientViaUserConsent(
ClientId clientId,
List<String> scopes,
PromptUserForConsent userPrompt, {
Client? baseClient,
String? hostedDomain,
int listenPort = 0,
String? customPostAuthPage,
AuthEndpoints authEndpoints = const GoogleAuthEndpoints(),
}) async {
var closeUnderlyingClient = false;
Expand All @@ -139,6 +145,7 @@ Future<AutoRefreshingAuthClient> clientViaUserConsent(
userPrompt,
hostedDomain: hostedDomain,
listenPort: listenPort,
customPostAuthPage: customPostAuthPage,
);

AccessCredentials credentials;
Expand Down Expand Up @@ -237,6 +244,8 @@ Future<AutoRefreshingAuthClient> clientViaUserConsentManual(
///
/// Generally you want to specify an explicit port so you can configure it
/// on the Google Cloud console.
///
/// {@macro googleapis_auth_custom_post_auth_page}
/// {@endtemplate}
Future<AccessCredentials> obtainAccessCredentialsViaUserConsent(
ClientId clientId,
Expand All @@ -245,6 +254,7 @@ Future<AccessCredentials> obtainAccessCredentialsViaUserConsent(
PromptUserForConsent userPrompt, {
String? hostedDomain,
int listenPort = 0,
String? customPostAuthPage,
AuthEndpoints authEndpoints = const GoogleAuthEndpoints(),
}) =>
AuthorizationCodeGrantServerFlow(
Expand All @@ -255,6 +265,7 @@ Future<AccessCredentials> obtainAccessCredentialsViaUserConsent(
userPrompt,
hostedDomain: hostedDomain,
listenPort: listenPort,
customPostAuthPage: customPostAuthPage,
).run();

/// Obtain oauth2 [AccessCredentials] using the oauth2 authentication code flow.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class AuthorizationCodeGrantServerFlow
extends AuthorizationCodeGrantAbstractFlow {
final PromptUserForConsent userPrompt;
final int listenPort;
final String? customPostAuthPage;

AuthorizationCodeGrantServerFlow(
super.authEndpoints,
Expand All @@ -34,6 +35,7 @@ class AuthorizationCodeGrantServerFlow
this.userPrompt, {
super.hostedDomain,
this.listenPort = 0,
this.customPostAuthPage,
});

@override
Expand Down Expand Up @@ -94,12 +96,12 @@ class AuthorizationCodeGrantServerFlow
codeVerifier: codeVerifier,
);

// TODO: We could introduce a user-defined redirect page.
request.response
..statusCode = 200
..headers.set('content-type', 'text/html; charset=UTF-8')
..write(
'''
customPostAuthPage ??
'''
<!DOCTYPE html>
<html>
Expand Down
2 changes: 1 addition & 1 deletion googleapis_auth/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: googleapis_auth
version: 1.5.1
version: 1.6.0
description: Obtain Access credentials for Google services using OAuth 2.0
repository: https://github.com/google/googleapis.dart/tree/master/googleapis_auth

Expand Down

0 comments on commit 1631558

Please sign in to comment.