Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/cmd/create/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod confidential;
mod public;

use crate::cmd::create::{confidential::CreateConfidential, public::CreatePublic};
use url::Url;
use openidconnect::IssuerUrl;

/// Create a new client
#[derive(Debug, clap::Parser)]
Expand Down Expand Up @@ -32,14 +32,18 @@ pub struct CreateCommon {
pub skip_initial: bool,

/// URL of the issuer
#[arg(long)]
pub issuer: Url,
#[arg(long, value_parser(parse_issuer))]
pub issuer: IssuerUrl,

/// Additional scope
#[arg(short = 'S', long)]
pub scope: Option<String>,
}

fn parse_issuer(s: &str) -> Result<IssuerUrl, anyhow::Error> {
Ok(IssuerUrl::new(s.to_string())?)
}

#[derive(Debug, clap::Subcommand)]
pub enum CreateType {
Confidential(CreateConfidential),
Expand Down
9 changes: 3 additions & 6 deletions src/cmd/create/public.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use oauth2::{
EndpointSet, PkceCodeChallenge, RedirectUrl, TokenResponse,
};
use openidconnect::{
AuthenticationFlow, IssuerUrl, Nonce,
AuthenticationFlow, Nonce,
core::{CoreClient, CoreProviderMetadata, CoreResponseType, CoreTokenResponse},
};
use std::path::PathBuf;
Expand Down Expand Up @@ -86,11 +86,8 @@ impl CreatePublic {

let http = create_client(&self.http).await?;

let provider_metadata = CoreProviderMetadata::discover_async(
IssuerUrl::from_url(self.common.issuer.clone()),
&http,
)
.await?;
let provider_metadata =
CoreProviderMetadata::discover_async(self.common.issuer.clone(), &http).await?;

let client = CoreClient::from_provider_metadata(
provider_metadata,
Expand Down
1 change: 1 addition & 0 deletions src/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mod token;
use std::process::ExitCode;

#[derive(Debug, clap::Subcommand)]
#[allow(clippy::large_enum_variant)]
pub enum Command {
Create(create::Create),
Delete(delete::Delete),
Expand Down
4 changes: 2 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use anyhow::{Context, anyhow};
use oauth2::TokenResponse;
use openidconnect::IssuerUrl;
use openidconnect::core::CoreTokenResponse;
use std::{
collections::BTreeMap,
fs::OpenOptions,
io::{BufReader, BufWriter, ErrorKind},
path::{Path, PathBuf},
};
use url::Url;

#[derive(Clone, Debug, Default, serde::Serialize, serde::Deserialize)]
pub struct Config {
Expand Down Expand Up @@ -83,7 +83,7 @@ impl Config {

#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct Client {
pub issuer_url: Url,
pub issuer_url: IssuerUrl,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub scope: Option<String>,
pub r#type: ClientType,
Expand Down
16 changes: 5 additions & 11 deletions src/oidc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use anyhow::{anyhow, bail};
use biscuit::{Empty, jws::Compact};
use oauth2::{EndpointMaybeSet, EndpointNotSet, EndpointSet, RefreshToken};
use openidconnect::{
Audience, ClientId, ClientSecret, IssuerUrl, Scope,
Audience, ClientId, ClientSecret, Scope,
core::{CoreClient, CoreProviderMetadata, CoreTokenResponse},
};
use time::OffsetDateTime;
Expand All @@ -29,11 +29,8 @@ pub async fn fetch_token(config: &Client, http: &HttpOptions) -> anyhow::Result<
client_id,
client_secret,
} => {
let provider_metadata = CoreProviderMetadata::discover_async(
IssuerUrl::from_url(config.issuer_url.clone()),
&http,
)
.await?;
let provider_metadata =
CoreProviderMetadata::discover_async(config.issuer_url.clone(), &http).await?;

let client = CoreClient::from_provider_metadata(
provider_metadata,
Expand All @@ -59,11 +56,8 @@ pub async fn fetch_token(config: &Client, http: &HttpOptions) -> anyhow::Result<
);
};

let provider_metadata = CoreProviderMetadata::discover_async(
IssuerUrl::from_url(config.issuer_url.clone()),
&http,
)
.await?;
let provider_metadata =
CoreProviderMetadata::discover_async(config.issuer_url.clone(), &http).await?;

let refresh_token = state.refresh_token.clone().ok_or_else(|| anyhow!("Expired token of a public client, without having a refresh token. You will need to re-login."))?;

Expand Down
Loading