@@ -18,7 +18,6 @@ const EXIT: [u8; 4] = [1, 3, 3, 7];
18
18
///
19
19
/// # Arguments
20
20
///
21
- /// * `response` - Optional static html string send to the user after being redirected. Keep it self-contained and as small as possible. Default: `"<html><body>Please return to the app.</body></html>"`.
22
21
/// * `handler` - Closure which will be executed on a successful connection. It receives the full URL as a String.
23
22
///
24
23
/// # Errors
@@ -32,12 +31,37 @@ pub fn start<F: FnMut(String) + Send + 'static>(handler: F) -> Result<u16, std::
32
31
start_with_config ( OauthConfig :: default ( ) , handler)
33
32
}
34
33
34
+ /// The optional server config.
35
35
#[ derive( Default , serde:: Deserialize ) ]
36
36
pub struct OauthConfig {
37
+ /// An array of hard-coded ports the server should try to bind to.
38
+ /// This should only be used if your oauth provider does not accept wildcard localhost addresses.
39
+ ///
40
+ /// Default: Asks the system for a free port.
37
41
pub ports : Option < Vec < u16 > > ,
42
+ /// Optional static html string send to the user after being redirected.
43
+ /// Keep it self-contained and as small as possible.
44
+ ///
45
+ /// Default: `"<html><body>Please return to the app.</body></html>"`.
38
46
pub response : Option < Cow < ' static , str > > ,
39
47
}
40
48
49
+ /// Starts the localhost (using 127.0.0.1) server. Returns the port its listening on.
50
+ ///
51
+ /// Because of the unprotected localhost port, you _must_ verify the URL in the handler function.
52
+ ///
53
+ /// # Arguments
54
+ ///
55
+ /// * `config` - Configuration the server should use, see [`OauthConfig.]
56
+ /// * `handler` - Closure which will be executed on a successful connection. It receives the full URL as a String.
57
+ ///
58
+ /// # Errors
59
+ ///
60
+ /// - Returns `std::io::Error` if the server creation fails.
61
+ ///
62
+ /// # Panics
63
+ ///
64
+ /// The seperate server thread can panic if its unable to send the html response to the client. This may change after more real world testing.
41
65
pub fn start_with_config < F : FnMut ( String ) + Send + ' static > (
42
66
config : OauthConfig ,
43
67
mut handler : F ,
@@ -208,7 +232,11 @@ mod plugin_impl {
208
232
}
209
233
}
210
234
211
- /// Initializes the plugin.
235
+ /// Initializes the tauri plugin.
236
+ /// Only use this if you need the JavaScript APIs.
237
+ ///
238
+ /// Note for the `start()` command: If `response` is not provided it will fall back to the config
239
+ /// in tauri.conf.json if set and will fall back to the library's default, see [`OauthConfig`].
212
240
#[ must_use]
213
241
pub fn init < R : Runtime > ( ) -> TauriPlugin < R > {
214
242
Builder :: new ( "oauth" )
0 commit comments