11use std:: {
2- ffi:: { CStr , c_void } ,
2+ ffi:: { c_void , CStr } ,
33 os:: raw:: c_char,
44 sync:: Arc ,
55} ;
@@ -8,8 +8,8 @@ use longport::Config;
88use time:: OffsetDateTime ;
99
1010use crate :: {
11- async_call:: { CAsyncCallback , execute_async } ,
12- error:: { CError , set_error } ,
11+ async_call:: { execute_async , CAsyncCallback } ,
12+ error:: { set_error , CError } ,
1313 types:: { CLanguage , CPushCandlestickMode , CString } ,
1414} ;
1515
@@ -120,6 +120,30 @@ pub unsafe extern "C" fn lb_config_new(
120120 Box :: into_raw ( Box :: new ( CConfig ( Arc :: new ( config) ) ) )
121121}
122122
123+ /// Create a new `Config` for OAuth 2.0 authentication
124+ ///
125+ /// OAuth 2.0 is the recommended authentication method that uses Bearer tokens
126+ /// and does not require app_secret or HMAC signatures.
127+ ///
128+ /// # Arguments
129+ ///
130+ /// - `client_id` - OAuth 2.0 client ID
131+ /// - `access_token` - OAuth 2.0 access token (Bearer prefix is optional)
132+ #[ unsafe( no_mangle) ]
133+ pub unsafe extern "C" fn lb_config_from_oauth (
134+ client_id : * const c_char ,
135+ access_token : * const c_char ,
136+ ) -> * mut CConfig {
137+ let client_id = CStr :: from_ptr ( client_id)
138+ . to_str ( )
139+ . expect ( "invalid client id" ) ;
140+ let access_token = CStr :: from_ptr ( access_token)
141+ . to_str ( )
142+ . expect ( "invalid access token" ) ;
143+ let config = Config :: from_oauth ( client_id, access_token) ;
144+ Box :: into_raw ( Box :: new ( CConfig ( Arc :: new ( config) ) ) )
145+ }
146+
123147/// Free the config object
124148#[ unsafe( no_mangle) ]
125149pub unsafe extern "C" fn lb_config_free ( config : * mut CConfig ) {
0 commit comments