@@ -66,14 +66,14 @@ pub(crate) type ReloadSessionCallback =
6666/// All the data relative to authentication, and that must be shared between a
6767/// client and all its children.
6868pub ( crate ) struct AuthCtx {
69- pub ( crate ) oauth : OAuthCtx ,
69+ oauth : OAuthCtx ,
7070
7171 /// Whether to try to refresh the access token automatically when an
7272 /// `M_UNKNOWN_TOKEN` error is encountered.
7373 pub ( crate ) handle_refresh_tokens : bool ,
7474
7575 /// Lock making sure we're only doing one token refresh at a time.
76- pub ( crate ) refresh_token_lock : Arc < AsyncMutex < Result < ( ) , RefreshTokenError > > > ,
76+ refresh_token_lock : Arc < AsyncMutex < Result < ( ) , RefreshTokenError > > > ,
7777
7878 /// Session change publisher. Allows the subscriber to handle changes to the
7979 /// session such as logging out when the access token is invalid or
@@ -84,7 +84,7 @@ pub(crate) struct AuthCtx {
8484 pub ( crate ) auth_data : OnceCell < AuthData > ,
8585
8686 /// The current session tokens.
87- pub ( crate ) tokens : OnceCell < Mutex < SessionTokens > > ,
87+ tokens : OnceCell < Mutex < SessionTokens > > ,
8888
8989 /// A callback called whenever we need an absolute source of truth for the
9090 /// current session tokens.
@@ -103,6 +103,20 @@ pub(crate) struct AuthCtx {
103103}
104104
105105impl AuthCtx {
106+ /// Construct a new `AuthCtx` with the given settings.
107+ pub ( crate ) fn new ( handle_refresh_tokens : bool , allow_insecure_oauth : bool ) -> Self {
108+ Self {
109+ handle_refresh_tokens,
110+ refresh_token_lock : Arc :: new ( AsyncMutex :: new ( Ok ( ( ) ) ) ) ,
111+ session_change_sender : broadcast:: Sender :: new ( 1 ) ,
112+ auth_data : OnceCell :: default ( ) ,
113+ tokens : OnceCell :: default ( ) ,
114+ reload_session_callback : OnceCell :: default ( ) ,
115+ save_session_callback : OnceCell :: default ( ) ,
116+ oauth : OAuthCtx :: new ( allow_insecure_oauth) ,
117+ }
118+ }
119+
106120 /// The current session tokens.
107121 pub ( crate ) fn session_tokens ( & self ) -> Option < SessionTokens > {
108122 Some ( self . tokens . get ( ) ?. lock ( ) . clone ( ) )
0 commit comments