pub struct OAuthTestServer {
pub base_url: Url,
pub endpoints: OauthEndpoints,
/* 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: OauthEndpointsImplementations§
Source§impl OAuthTestServer
impl OAuthTestServer
pub async fn start() -> Self
pub fn clients(&self) -> Arc<RwLock<HashMap<String, Client>>>
pub fn codes(&self) -> Arc<RwLock<HashMap<String, AuthorizationCode>>>
pub fn tokens(&self) -> Arc<RwLock<HashMap<String, Token>>>
pub fn refresh_tokens(&self) -> Arc<RwLock<HashMap<String, Token>>>
pub async fn start_with_config(config: IssuerConfig) -> Self
pub async fn wait_for_shutdown(self) -> Result<(), JoinError>
pub fn register_client(&self, metadata: Value) -> Client
pub fn register_client_with_secret( &self, metadata: Value, force_secret: bool, ) -> Client
pub fn generate_jwt(&self, client: &Client, options: JwtOptions) -> String
pub fn generate_token(&self, client: &Client, options: JwtOptions) -> Token
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
Auto Trait Implementations§
impl Freeze for OAuthTestServer
impl !RefUnwindSafe for OAuthTestServer
impl Send for OAuthTestServer
impl Sync for OAuthTestServer
impl Unpin 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