pub struct DingtalkAuthPlugin {
app_key: String,
app_secret: String,
code_header: String,
code_query: String,
token_url: String,
userinfo_url: String,
set_userinfo_header: bool,
timeout: Duration,
ssl_verify: bool,
resources: Arc<PluginResources>,
token_cache: Mutex<Option<(String, Instant)>>,
}Expand description
Authenticates requests by resolving a DingTalk authorization code to a
DingTalk user via the OAuth accessToken + getuserinfo APIs.
Fields§
§app_key: String§app_secret: String§code_header: StringLowercased header the code is read from first.
code_query: StringQuery parameter the code falls back to.
token_url: String§userinfo_url: String§set_userinfo_header: bool§timeout: Duration§ssl_verify: bool§resources: Arc<PluginResources>§token_cache: Mutex<Option<(String, Instant)>>In-process cache of the app-level access token: (token, fetched_at).
Implementations§
Source§impl DingtalkAuthPlugin
impl DingtalkAuthPlugin
Sourcepub fn from_config(
config: &HashMap<String, Value>,
resources: &Arc<PluginResources>,
) -> Result<Self, String>
pub fn from_config( config: &HashMap<String, Value>, resources: &Arc<PluginResources>, ) -> Result<Self, String>
Builds the plugin from node config.
Accepted keys:
app_key(string, required): DingTalk application key.app_secret(string, required): DingTalk application secret.code_header(string, default"X-DingTalk-Code"): header the authorization code is read from first (matched case-insensitively).code_query(string, default"code"): query parameter the code falls back to when the header is absent.access_token_url(string, default DingTalk’soauth2/accessToken).userinfo_url(string, default DingTalk’sv2/user/getuserinfo).set_userinfo_header(bool, defaulttrue): when true the resolved userinfo JSON is base64-encoded into theX-Userinforequest header for the upstream.timeout(integer ms, default6000): per-callout timeout.ssl_verify(bool, defaulttrue): verify DingTalk’s TLS certificate.
Session-only APISIX keys (secret, secret_fallbacks, redirect_uri,
cookie_expires_in) are not accepted — see the module docs.
type: dingtalk-auth
config:
app_key: ${DINGTALK_APP_KEY}
app_secret: ${DINGTALK_APP_SECRET}
code_header: X-DingTalk-CodeSourcefn extract_code(&self, ctx: &Context) -> Option<String>
fn extract_code(&self, ctx: &Context) -> Option<String>
Reads the authorization code from the configured header, falling back to the query parameter.
Sourceasync fn access_token(&self) -> Result<String, DingtalkError>
async fn access_token(&self) -> Result<String, DingtalkError>
Returns a valid access token, using the in-process cache when fresh and fetching a new one from DingTalk otherwise.
Sourceasync fn fetch_userinfo(
&self,
access_token: &str,
code: &str,
) -> Result<Value, DingtalkError>
async fn fetch_userinfo( &self, access_token: &str, code: &str, ) -> Result<Value, DingtalkError>
Exchanges the code for DingTalk userinfo using access_token.
Sourcefn reject(
ctx: Context,
message: &str,
) -> Result<PluginOutput, PluginExecutionError>
fn reject( ctx: Context, message: &str, ) -> Result<PluginOutput, PluginExecutionError>
Builds the 401 rejection carrying the context so the graph engine
routes through the error port.
Trait Implementations§
Source§impl Plugin for DingtalkAuthPlugin
impl Plugin for DingtalkAuthPlugin
Source§fn plugin_type(&self) -> &str
fn plugin_type(&self) -> &str
Source§fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: Context,
_named_inputs: &'life1 HashMap<String, Value>,
) -> Pin<Box<dyn Future<Output = Result<PluginOutput, PluginExecutionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: Context,
_named_inputs: &'life1 HashMap<String, Value>,
) -> Pin<Box<dyn Future<Output = Result<PluginOutput, PluginExecutionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Auto Trait Implementations§
impl !Freeze for DingtalkAuthPlugin
impl !RefUnwindSafe for DingtalkAuthPlugin
impl Send for DingtalkAuthPlugin
impl Sync for DingtalkAuthPlugin
impl Unpin for DingtalkAuthPlugin
impl UnsafeUnpin for DingtalkAuthPlugin
impl !UnwindSafe for DingtalkAuthPlugin
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more