外观
finSmtp
原文: https://finproducts.atlassian.net/wiki/spaces/JIDD3/pages/34793914413/FIN+5.3.1+finSmtp 中文整理基于 FIN 5.3.1
finSmtp
西门子 Desigo Optic SMTP Oauth 库
mixins
| AccessToken | OAuth2 访问令牌 |
| FinSmtpService | |
| SimpleProcess | 具有返回成功状态的启动和停止功能的进程基类 |
classes
| AuthCodeTokenReq | 授权码授权类型的令牌请求。 |
| AuthCredentials | |
| AuthReq | 用于授权码请求的基类 |
| DiscoveryRequest | 请求所有查找的发现信息。 |
| FinAuthReq | |
| FinSmtpLib | |
| FinSmtpMod | |
| FinSmtpWeb | |
| IdentityTokenValidator | 验证 JWT 身份令牌。 |
| JsonAccessToken | JSON 访问令牌 (RFC 6749 §5.1) |
| JwksRequest | 请求 JSON Web 密钥。 |
| LoopbackAuthReq | 如果授权服务器被配置为重定向到本地主机,那么这个类可以用来进行授权请求。 |
| OAuthClient | OAuthClient |
| RawAccessToken | 原始访问令牌 - 允许您显式构建访问令牌并设置所有字段。 |
| SmtpClient | SmtpClient 实现了 RFC 2821 指定的 SMTP(简单邮件传输协议)客户端功能。 |
| TokenReq | 所有令牌请求的基类 |
facets
| ProcessMsgHandler | 用于装饰处理方法以接收消息的 Facet 类 |
errs
| AuthReqErr | AuthReqErr |
| OAuthErr | |
| SmtpErr | SmtpErr 表示在 SMTP 事务期间发生错误。 |
AccessToken
const 混入 AccessToken
OAuth2 访问令牌
方法
| accessToken | The acces token |
| expiresIn | 直到令牌过期还有多久(如果服务器指定的话) |
| hasRefreshToken | 如果令牌包含刷新令牌,则返回 true |
| refreshToken | 如果存在,请获取刷新令牌 |
| scope | 该令牌的作用范围 |
| tokenType | 访问令牌类型(例如 |
插槽详情
accessToken
抽象 Str accessToken()
访问令牌
expiresIn
抽象 Duration? expiresIn()
直到令牌过期还有多久(如果服务器指定的话)
hasRefreshToken
Bool 有刷新令牌()
如果令牌包含刷新令牌,则返回 true
refreshToken
抽象 Str? refreshToken()
如果存在,请获取刷新令牌
scope
抽象 Str[] 范围()
该令牌的作用范围
tokenType
抽象 Str tokenType()
访问令牌类型(例如“Bearer”)
AuthCodeTokenReq
const class AuthCodeTokenReq : TokenReq
授权码授权类型的令牌请求。
构造函数
| make |
字段
| grantType |
方法
| grant |
插槽详情
grant
虚拟重写 AccessToken grant(AuthReq req, Str:Str flowParams)
grantType
虚拟 const 重写 Str grantType := "authorization_code"
make
new make(Uri tokenUri, Str:Str customParams := [:])
AuthCredentials
const class AuthCredentials : Obj
构造函数
| make |
字段
| clientId | |
| clientSecret | |
| idp |
方法
| toDict |
插槽详情
clientId
const Str clientId
clientSecret
const Str clientSecret
idp
常量 Str idp
make
new make(Str idp, Str clientSecret, Str clientId)
toDict
转为字典()
AuthReq
抽象常量类 AuthReq : Obj
用于授权码请求的基类
构造函数
| make |
字段
| authUri | |
| clientId | |
| customParams | |
| redirectUri | |
| scopes |
方法
| authorize | |
| build | |
| responseType |
插槽详情
authUri
const Uri 认证Uri
authorize
抽象 Str:Str 授权(Str:Str flowParams)
build
虚拟 Str:Str build()
clientId
const Str clientId
customParams
const Str:Str customParams := [Str:Str][:]
make
new make(Uri authUri, Str clientId, This ? f := null)
redirectUri
const Uri? 重定向Uri
responseType
抽象 Str responseType()
scopes
const Str[]? 范围
AuthReqErr
const class AuthReqErr : Err
AuthReqErr
构造函数
| make |
字段
| params | 原始错误信息 |
方法
| desc | |
| error | |
| toStr |
插槽详情
desc
字符串 desc()
error
Str 错误()
make
new make(Str:Str 参数, Err? cause := null)
params
const Str:Str 参数
原始错误信息
toStr
虚拟重写 Str toStr()
DiscoveryRequest
const class DiscoveryRequest : Obj
请求所有查找的发现信息。
构造函数
| make |
方法
| get | 返回发现参数中的条目,如果未找到则返回空。 |
插槽详情
get
Str? 获取(Str id)
返回发现参数中的条目,如果未找到则返回空。
make
new make(Uri discoveryEndpointUri)
FinAuthReq
const 类 FinAuthReq : AuthReq
构造函数
| make |
字段
| responseType |
方法
| authorize |
插槽详情
authorize
虚拟重写 Str:Str authorize(Str:Str flowParams)
make
new make(Uri authUri, Str clientId, This ? f := null)
responseType
虚拟 const 覆盖 Str responseType := "code"
FinSmtpLib
const 类 FinSmtpLib : Obj
方法
| finEmailSend | 同步发送电子邮件:- 收件人:以下之一 |
| finEmailSendAsync | |
| finEmailSendTest | 同步发送测试电子邮件并返回跟踪信息 |
插槽详情
finEmailSend
@Axon Obj? finEmailSend(Obj recipients, Str subject, Obj content, Obj? attachments := null)
同步发送电子邮件:
收件人:以下之一:用于“收件人”的字符串电子邮件地址 用于“收件人”的字符串电子邮件地址列表 包含“to”、“cc”或“bcc”的字典,其值为字符串或字符串数组 主题:字符串 主题文本 内容:字符串 邮件正文文本。如果内容以“<html ”开头,则以“text/html”格式发送,否则以“text/plain”格式发送 附件:以下任意一种或列表将作为文件附件包含:文件 io 句柄 App 报告引用将作为 PDF 文件附加 App 报告记录的字典将作为 PDF 文件附加 Grid[](Grid 列表)将被视为复合报告并作为 PDF 文件附加 导出请求字典
finEmailSendAsync
@Axon Future finEmailSendAsync(Obj 收件人, Str 主题, Obj 内容, Obj? 附件 := null)
finEmailSendTest
@Axon Obj? finEmailSendTest(Obj recipients, Str subject, Obj content)
同步发送测试电子邮件并返回跟踪信息
FinSmtpMod
const class FinSmtpMod : SysMod
构造函数
| make |
字段
| api | |
| lib | |
| web |
方法
| getAuthToken | |
| onReceive | 在后台演员线程上处理 |
| onStart | |
| send | 异步发送电子邮件 |
| sendTest | 以测试模式异步发送电子邮件并返回跟踪字符串 |
插槽详情
api
const static Str api := "finSmtp"
getAuthToken
Str? 获取身份验证令牌()
lib
const FinSmtpLib lib := ...
make
new make()
onReceive
虚拟重写 Obj? onReceive(HxMsg msg)
在后台演员线程上处理
onStart
虚拟重写 Void onStart()
send
将来发送(电子邮件 email)
异步发送电子邮件
sendTest
未来发送测试(电子邮件 email)
以测试模式异步发送电子邮件并返回跟踪字符串
web
virtual const override FinSmtpWeb web := FinSmtpWeb.<ctor (this, this.fss)
FinSmtpService
混入 FinSmtpService
方法
| authenticate | |
| getAuthCredentials | |
| getAuthToken | |
| getCallbackUri | |
| getRedirectRoute | |
| setAuthCredentials | |
| setRedirectRoute |
插槽详情
authenticate
抽象布尔值 authenticate(字符串 authCode, 字符串 state)
getAuthCredentials
抽象 AuthCredentials? getAuthCredentials()
getAuthToken
抽象 Str? getAuthToken()
getCallbackUri
抽象 Str? getCallbackUri()
getRedirectRoute
抽象 Str getRedirectRoute()
setAuthCredentials
抽象 Bool setAuthCredentials(Str idp, Str clientId, Str clientSecret)
setRedirectRoute
抽象布尔类型 setRedirectRoute(字符串 redirectRoute)
FinSmtpWeb
const class FinSmtpWeb : SysWeb
构造函数
| make |
方法
| onService |
插槽详情
make
new make(SysMod mod, FinSmtpService fss)
onService
虚拟重写 Void onService()
IdentityTokenValidator
class IdentityTokenValidator : Obj
验证 JWT 身份令牌。
构造函数
| make |
字段
| claims | |
| header |
方法
| validate | 验证身份令牌,如果有问题则抛出错误。 |
插槽详情
claims
const Str:Obj 声明
header
const Str:Str 头
make
new make(Str identityToken, Uri issuer, Str clientId, Str nonce, Str- [Str:Str]? getJwk, DateTime now := DateTime.now())
validate
IdentityTokenValidator 验证()
验证身份令牌,如果有问题则抛出错误。
https://openid.net/specs/openid-connect-core-1_0.html ID令牌验证
JsonAccessToken
const class JsonAccessToken : Obj, AccessToken
JSON 访问令牌 (RFC 6749 §5.1)
构造函数
| fromStr | |
| make |
字段
| json |
方法
| accessToken | |
| expiresIn | |
| idToken | |
| refreshToken | |
| scope | |
| toStr | |
| tokenType |
插槽详情
accessToken
虚拟重写 Str accessToken()
expiresIn
虚拟重写 Duration? expiresIn()
fromStr
static new fromStr(Str json)
idToken
Str? idToken()
json
const Str:Obj? json
make
new make(Str:Obj? json)
refreshToken
虚拟重写 Str? refreshToken()
scope
虚拟重写 Str[] 范围()
toStr
虚拟重写 Str toStr()
tokenType
虚拟重写 Str tokenType()
JwksRequest
const 类 JwksRequest : Obj
请求 JSON Web 密钥。
构造函数
| make |
方法
| getAll | |
| getJwk | 返回密钥 ID 的 JSON 网密钥,如果找不到则返回 null。 |
插槽详情
getAll
Str:Str[]? 获取所有()
getJwk
[Str:Str]? 获取Jwk(Str kid)
返回密钥 ID 的 JSON 网密钥,如果找不到则返回 null。
make
new make(DiscoveryRequest discovery)
LoopbackAuthReq
const class LoopbackAuthReq : AuthReq
如果授权服务器被配置为重定向到本地主机,那么可以使用此类进行授权请求。它会打开一个浏览器窗口,让用户使用远程授权服务器授权访问。它将在本地主机上生成一个 Web 服务器来处理授权服务器在授予或拒绝授权访问后所进行的重定向。如果授权成功,我们会从生成的 Web 服务器中获取授权码,以便授权码授权流程可以继续。
构造函数
| make |
字段
| responseType |
方法
| authorize |
插槽详情
authorize
虚拟重写 Str:Str authorize(Str:Str flowParams)
make
new make(Uri authUri, Str clientId, This ? f := null)
responseType
虚拟 const 覆盖 Str responseType := "code"
OAuthClient
const class OAuthClient : Obj
OAuthClient
构造函数
| make | 使用提供的访问令牌创建一个基本的 OAuth 客户端。 |
| makeRefreshable | 创建一个支持令牌刷新(token refresh)的 OAuth 客户端。 |
方法
| call | 使用指定的方法(GET、PUT 等)对给定的 URI 进行 HTTP 请求。 |
| prepare | 用于获取一个设置了 URI、方法和头(包括 Bearer 令牌)的原始 WebClient 的工具 |
| readJson | |
| token |
插槽详情
call
WebClient 调用(Str 方法, Uri uri, Obj? 请求 := null, Str:Str 头部 := ...)
使用给定的方法(GET、PUT 等)向指定的 URI 发出 HTTP 请求。你也可以传递额外的头信息随请求一起发送。此方法将处理 OAuth 令牌刷新。
如果 req 参数非空,它将首先按照下文所述转换为文件,然后作为请求正文写入(参见 WebClient.writeFile)。
- 文件:未进行转换,文件按原样写入 缓冲区:使用 Buf.toFile 转换为文件。内容类型将是 application/octet-stream。映射:编码为 JSON 并作为带有 .json 扩展名的文件写入。
返回一个 WebClient,其状态为已调用 WebClient.readRes 并且 WebClient.resIn 可供读取。
make
new make(AccessToken 令牌)
使用给定的访问令牌创建一个基本的 OAuthClient。不支持令牌刷新。
makeRefreshable
new makeRefreshable(AccessToken token, Uri tokenUri, Str:Str params)
创建一个支持令牌刷新(token refresh)的OAuth客户端。tokenUri是用于刷新令牌的端点。参数必须至少包括client_id参数。
prepare
WebClient 准备(Str 方法, Uri uri, Str:Str 头部 := ...)
用于获取一个设置了 URI、方法和头(包括 Bearer 令牌)的原始 WebClient 的工具
readJson
受保护的静态 Map 读取 Json(Str str)
token
受保护的 AccessToken token()
OAuthErr
const class OAuthErr : Err
构造函数
| make |
字段
| body | |
| code |
方法
| toStr |
插槽详情
body
const Str body
code
const Int 代码
make
new make(WebClient c)
toStr
虚拟重写 Str toStr()
ProcessMsgHandler
@Serializable 方面类 ProcessMsgHandler : Obj, Facet
用于装饰处理方法以接收消息的 Facet 类
字段
| msgId |
插槽详情
msgId
const Obj msgId := ""
RawAccessToken
const class RawAccessToken : Obj, AccessToken
原始访问令牌 - 允许您显式构建访问令牌并设置所有字段。
构造函数
| make |
字段
| accessToken | |
| expiresIn | |
| refreshToken | |
| scope | |
| tokenType |
方法
| toStr |
插槽详情
accessToken
虚拟 const 重写 Str accessToken
expiresIn
虚拟的常量重写 Duration? expiresIn
make
new make(Str accessToken, This ? f := null)
refreshToken
虚拟常量重写 Str? refreshToken
scope
虚拟 const 重写 Str[] scope := Str.emptyList
toStr
虚拟重写 Str toStr()
tokenType
虚拟 const 覆盖 Str tokenType := "Bearer"
SimpleProcess
const mixin 简单流程
具有返回成功状态的启动和停止功能的进程基类
方法
| start | 启动过程,等待结果 |
| startAsync | 在单独的线程上异步启动该过程,并立即返回 |
| stop | |
| stopAsync |
插槽详情
start
抽象 Bool start(Obj? arg := null)
启动过程,等待结果
startAsync
抽象 Void startAsync(Obj? arg := null)
在单独的线程上异步启动该过程,并立即返回
stop
抽象 Bool stop(Obj? arg := null)
stopAsync
抽象 Void stopAsync(Obj? arg := null)
SmtpClient
类 SmtpClient : Obj
SmtpClient 实现了 RFC 2821 指定的 SMTP(简单邮件传输协议)客户端功能。
请参阅 pod 文档和示例。
字段
| host | 服务器的 DNS 主机名。 |
| oauth | 启用 OAuth 授权,默认为 false。 |
| password | 用于身份验证的密码,或为 null 以跳过身份验证。 |
| port | 服务器的TCP端口号,默认为25。 |
| socketConfig | 用于创建套接字的 SocketConfig。 |
| ssl | 使用 SSL/TLS 打开连接(确保端口配置正确)。 |
| username | 用于身份验证的用户名,或为 null 以跳过身份验证。 |
方法
| authCramMd5 | 使用 CRAM-MD5 机制进行身份验证。 |
| authLogin | 使用 LOGIN 机制进行身份验证。 |
| authPlain | 使用 PLAIN 机制进行认证。 |
| authXOAuth2 | |
| authenticate | 使用服务器和我都支持的最强身份验证机制进行身份验证。 |
| close | 关闭与 SMTP 服务器的会话。 |
| isClosed | 如果没有打开的会话,则返回 true。 |
| open | 打开与 SMTP 服务器的会话。 |
| send | 将电子邮件发送到 SMTP 服务器。 |
插槽详情
authCramMd5
无效 authCramMd5()
使用 CRAM-MD5 机制进行身份验证。
authLogin
无效 authLogin()
使用 LOGIN 机制进行身份验证。
authPlain
空 authPlain()
使用 PLAIN 机制进行认证。
authXOAuth2
空 void authXOAuth2()
authenticate
空 验证()
使用服务器和我都支持的最强身份验证机制进行身份验证。
close
空 close()
关闭与 SMTP 服务器的会话。如果会话已关闭,则不执行任何操作。
host
字符串?主机
服务器的 DNS 主机名。
isClosed
Bool isClosed()
如果没有打开的会话,则返回 true。
oauth
布尔型 oauth := 假
启用 OAuth 授权,默认为 false。
open
空 void open()
打开与 SMTP 服务器的会话。如果配置了用户名和密码,则尝试进行 SMTP 身份验证。如果发生协议错误,则抛出 SmtpErr。如果存在网络问题,则抛出 IOErr。
password
字符串密码
用于身份验证的密码,或为 null 以跳过身份验证。
port
整数 端口 := 25
服务器的TCP端口号,默认为25。
send
空 send(电子邮件 email)
将电子邮件发送到 SMTP 服务器。如果出现协议错误,则抛出 SmtpErr。如果出现网络问题,则抛出 IOErr。如果会话已关闭,则此调用会自动打开会话,并保证在完成后关闭会话。
socketConfig
SocketConfig socketConfig := SocketConfig.cur
用于创建套接字的 SocketConfig。
ssl
布尔 SSL
使用 SSL/TLS 打开连接(确保端口配置正确)。如果为 false,则连接以明文方式打开,但如果服务器指定 STARTTLS,仍可能升级为 TLS。
username
字符串?用户名
用于身份验证的用户名,或为 null 以跳过身份验证。
SmtpErr
const class SmtpErr : Err
SmtpErr 表示在 SMTP 事务期间发生错误。
构造函数
| make | 使用错误代码、消息和可选原因构造。 |
字段
| code | RFC 2821 定义的 SMTP 错误代码 |
插槽详情
code
const Int 代码
RFC 2821 定义的 SMTP 错误代码
make
new make(Int code, Str? msg, Err? cause := null)
使用错误代码、消息和可选原因构造。
TokenReq
抽象常量类 TokenReq : Obj
所有令牌请求的基类
构造函数
| make | 构建一个 TokenReq。 |
字段
| customParams | |
| tokenUri |
方法
| build | |
| grant | |
| grantType |
插槽详情
build
虚拟 Str:Str build()
customParams
const Str:Str 自定义参数
grant
抽象 AccessToken 授权(AuthReq authReq, Str:Str flowParams)
grantType
抽象 Str grantType()
make
new make(Uri tokenUri, Str:Str customParams := [:])
构建一个 TokenReq。tokenUri 是进行令牌请求的端点。您还可以指定应包含在令牌请求中的其他自定义参数。
tokenUri
const Uri 令牌Uri