pub struct OAuthTestServer {
pub base_url: Url,
pub endpoints: OauthEndpoints,
pub http: Client,
/* private fields */
}Expand description
Start a test server with full programmatic control.
use oauth2_test_server::OAuthTestServer;
#[tokio::test]
async fn test() {
let server = OAuthTestServer::start().await;
println!("server: {}", server.base_url());
println!("authorize endpoint: {}", server.endpoints.authorize_url);
// register a client
let client = server.register_client(
serde_json::json!({ "scope": "openid", "redirect_uris":["http://localhost:8080/callback"]}),
);
// generate a jwt
let jwt = server.generate_jwt(&client, server.jwt_options().user_id("bob").build());
assert_eq!(jwt.split('.').count(), 3);
assert_eq!(server.clients().read().iter().len(), 1);
assert_eq!(server.tokens().read().iter().len(), 1);
}Fields§
§base_url: Url§endpoints: OauthEndpoints§http: ClientImplementations§
Source§impl OAuthTestServer
impl OAuthTestServer
pub async fn start() -> Self
pub async fn start_with_config(config: IssuerConfig) -> Self
pub async fn wait_for_shutdown(self) -> Result<(), JoinError>
pub async fn register_client(&self, metadata: Value) -> Client
pub async fn register_client_with_secret( &self, metadata: Value, force_secret: bool, ) -> Client
pub fn generate_jwt(&self, client: &Client, options: JwtOptions) -> String
pub async fn generate_token( &self, client: &Client, options: JwtOptions, ) -> Token
pub async fn clients(&self) -> Vec<Client>
pub async fn codes(&self) -> Vec<AuthorizationCode>
pub async fn tokens(&self) -> Vec<Token>
pub async fn refresh_tokens(&self) -> Vec<Token>
pub async fn clear_clients(&self)
pub async fn clear_codes(&self)
pub async fn clear_tokens(&self)
pub async fn clear_refresh_tokens(&self)
pub async fn clear_device_codes(&self)
pub async fn clear_all(&self)
pub async fn approve_device_code(&self, device_code: &str, user_id: &str)
pub fn state(&self) -> &AppState
pub fn jwt_options(&self) -> JwtOptionsBuilder
pub fn pkce_pair(&self) -> PkcePair
pub fn rotate_keys(&self)
pub async fn approve_consent(&self, auth_url: &Url, user_id: &str) -> String
pub async fn exchange_code( &self, client: &Client, code: &str, pkce: Option<&PkcePair>, ) -> Value
pub async fn refresh_token(&self, client: &Client, refresh_token: &str) -> Value
pub async fn introspect_token(&self, client: &Client, token: &str) -> Value
pub async fn revoke_token(&self, client: &Client, token: &str)
pub fn client_assertion_jwt(&self, client: &Client) -> String
pub fn base_url(&self) -> &Url
pub fn issuer(&self) -> &str
Sourcepub async fn complete_auth_flow(
&self,
client: &Client,
params: AuthorizeParams,
user_id: &str,
) -> Value
pub async fn complete_auth_flow( &self, client: &Client, params: AuthorizeParams, user_id: &str, ) -> Value
Complete the full authorization code flow with PKCE in one call. Returns the token response including access_token, refresh_token, and optionally id_token.
Auto Trait Implementations§
impl Freeze for OAuthTestServer
impl !RefUnwindSafe for OAuthTestServer
impl Send for OAuthTestServer
impl Sync for OAuthTestServer
impl Unpin for OAuthTestServer
impl UnsafeUnpin for OAuthTestServer
impl !UnwindSafe for OAuthTestServer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more