Improve clarity on redirect URLs for #191

This commit is contained in:
Lewin Bormann
2023-02-10 20:59:01 +01:00
parent 1c6f9a7d56
commit 0a7e695971
2 changed files with 17 additions and 0 deletions

View File

@@ -156,3 +156,11 @@ impl DeviceFlowDelegate for DefaultDeviceFlowDelegate {}
#[derive(Copy, Clone)]
pub struct DefaultInstalledFlowDelegate;
impl InstalledFlowDelegate for DefaultInstalledFlowDelegate {}
/// The default installed-flow delegate (i.e.: show URL on stdout). Use this to specify
/// a custom redirect URL.
#[derive(Clone)]
pub struct DefaultInstalledFlowDelegateWithRedirectURI(pub String);
impl InstalledFlowDelegate for DefaultInstalledFlowDelegateWithRedirectURI {
fn redirect_uri(&self) -> Option<&str> { Some(self.0.as_str()) }
}

View File

@@ -91,6 +91,15 @@ pub struct InstalledFlow {
impl InstalledFlow {
/// Create a new InstalledFlow with the provided secret and method.
///
/// In order to specify the redirect URL to use (in the case of `HTTPRedirect` or
/// `HTTPPortRedirect` as method), either implement the `InstalledFlowDelegate` trait, or
/// use the `DefaultInstalledFlowDelegateWithRedirectURI`, which presents the URL on stdout.
/// The redirect URL to use is configured with the OAuth provider, and possible options are
/// given in the `ApplicationSecret.redirect_uris` field.
///
/// The `InstalledFlowDelegate` implementation should be assigned to the `flow_delegate` field
/// of the `InstalledFlow` struct.
pub(crate) fn new(
app_secret: ApplicationSecret,
method: InstalledFlowReturnMethod,