Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QRCode login support & Introduce new authorization factory #2502

Merged
merged 65 commits into from
Mar 18, 2023

Conversation

StageGuard
Copy link
Member

@StageGuard StageGuard commented Feb 15, 2023

QRCode Login

  • protocol
  • api
  • test
  • document

brief intro of New Authorization

Provide:

public fun newBot(id: Long, authorizer: BotAuthorizer, config: BotConfiguration)
public interface BotAuthorizer {
    public suspend fun authorize(session: AuthSession)
    companion object {
        public suspend fun byPassword(password: String): BotAuthorizer { /* default implementation */ }
        public suspend fun byQRCodeScan(listener: QRCodeLoginListener): BotAuthorizer  { /* default implementation */ }
    }
}

public interface AuthSession {
    public val qq: Long

    public suspend fun loginByPassword(password: String): AuthResult
    public suspend fun loginByPassword(passwordMd5: ByteArray): AuthResult

    public suspend fun loginByQRScan(qrListener: QRCodeLoginListener): AuthResult
//    public suspend fun loginBySms(smsListener: …): AuthResult
}

Users can implement custom authorizer instead of default implementations like:

object : BotAuthorizer {
    override suspend fun authorize(session: AuthSession) {
        runCatching {
            session.authByQRCode()
        }.recover {
            session.authByPassword()
        }.recover { /* .... */ }
    }
}

@StageGuard
Copy link
Member Author

StageGuard commented Feb 15, 2023

image
已经可以登录,但是还有其他问题:

  • Logger name 依旧显示为 Bot 0
  • wtlogin.trans_emp 协议不稳定,经常无法解析。

@Him188 Him188 added this to the 2.15.0-RC milestone Feb 15, 2023
@Him188 Him188 added t:feature 类型: 新特性 x:protocol 属性: 协议相关 s:core 子系统: mirai-core labels Feb 15, 2023
@StageGuard StageGuard marked this pull request as ready for review February 15, 2023 12:30
@Karlatemp Karlatemp self-requested a review February 15, 2023 14:18
This was linked to issues Feb 15, 2023
@Him188 Him188 self-requested a review February 15, 2023 17:31
@msojocs

This comment was marked as off-topic.

@StageGuard StageGuard changed the title QRCode login support QRCode login support $ Introduce new authorization factory Feb 20, 2023
@StageGuard StageGuard changed the title QRCode login support $ Introduce new authorization factory QRCode login support & Introduce new authorization factory Feb 20, 2023
@Him188
Copy link
Member

Him188 commented Mar 3, 2023

提醒一下,
不要 force push

@cssxsh cssxsh mentioned this pull request Mar 8, 2023
@Him188 Him188 modified the milestones: 2.15.0-RC, 2.15.0-M1 Mar 11, 2023
@Him188 Him188 requested a review from Karlatemp March 12, 2023 17:13
Copy link
Member

@Karlatemp Karlatemp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 给productor也添加相关测试
  2. productor 感觉更像是通用工具类,换个包更好

mirai-core/src/commonMain/kotlin/network/auth/Latch.kt Outdated Show resolved Hide resolved
@Him188
Copy link
Member

Him188 commented Mar 13, 2023

TODO:

  • OnDemandProducer test
  • 登录的 test 如果还有需要
  • 检查 Latch 实现

@Him188 Him188 merged commit 78d0b4f into mamoe:dev Mar 18, 2023
StageGuard added a commit to StageGuard/mirai that referenced this pull request Apr 14, 2023
* [core] process `wtlogin.trans_emp` to support qrcode login

* [core] fix `wtlogin.trans_emp` protocol

* [core] optimize QRCodeLoginProcessor logic

* [core] fix `wtlogin.trans_emp` outgoing packet

* [core] cancel login when logging a bot which is inconsistent from bot factory

* [core] ignore `flag3` check on ANDROID_WATCH & name `flag1` and `flag2`

* [core] provide default `QRCodeLoginListener` for jvm

* [core] don't catch IllegalStateException in QRCodeLoginProcessor

* [core] Use `LoginSolver.createQRCodeLoginListener()` instead of property; Rename configuration name

* [core] Code improvement

* [core] remove qrcode state lock

* [core] ignore `flag3` when command is `wtlogin.trans_emp` in packet codec

* [core] enable qrcode login for macos

* [core] remove debug property in log

* [core] reformat code

* [core] rename `TransEmpResponse` to `Response`

* [core] assert `flag3Exception` not null first

* [core] remove arg client

* [core] update qrcode login notes

* [core] set custom qrcode size

* [core] Draft BotAuthorization

* [core] make SecretsProtection mpp

* [core] BotAuthorization.byXXX

* [core] Move QRCodeLoginListener to `.auth`

* [core] Protect data of BotAccount

* [core] Add SelectorRequireReconnectException

* [core] Implementation of BotAuthorization

* Revert changes of BotConfiguration

* api dump

* [core] remove passwordMd5 in `BotAccount`

* [mock] Add new bot factory function to mock bot factory

* Delete LoginCommandTest

* [core] Improve QRCode render

* [core] Introduce UnsupportedCaptchaMethodException & UnsupportedQRCodeCaptchaException

* api dump

* update docs

* [core] update `DebugRunHelper`

* [core] add simple block for BotAuthorization

* api dump

* Rename `canDoQRLogin` to `supportsQRLogin`, and specify argument names for MiraiProtocolInternal

* Remove `phoneNumber` parameter from BotAccount

* Make `BotAccount.<init>` with String password parameter TestOnly

* Rename `InconsistentBotException` to `InconsistentBotIdException`

* Rename `QRCodeLoginListener.onStatusChanged` to `QRCodeLoginListener.onStateChanged`

* Rename `BotAuthorizationResult` to `BotAuthResult`

* Rename BotAuthComponent, move internal APIs to internal module

* Logic fixup

* doc update

* QRCodeLoginListener.qrCodeStateUpdateInterval & onIntervalLoop

* console login with BotAuthorization

* update testing

* Update mirai-core-api/src/jvmMain/kotlin/utils/LoginSolver.jvm.kt

* Move AuthControl outside SsoProcessor

* Redesign auth

* Add initialTicket to producerCoroutine

* Revert protocol changes of MACOS

* Fix latch death locking

* Fix CoroutineOnDemandValueScope.receiveOrNull exceptional finish

* Fix exception collecting

* Fix DefaultBotAuthorizationFactory loading

* [core] qrcode login for IPAD protocol

* Revert "[core] qrcode login for IPAD protocol"

This reverts commit c1136a8.

---------

Co-authored-by: Karlatemp <kar@kasukusakura.com>
Co-authored-by: Him188 <Him188@mamoe.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
s:core 子系统: mirai-core t:feature 类型: 新特性 x:protocol 属性: 协议相关
Projects
None yet
Development

Successfully merging this pull request may close these issues.

支持二维码扫码登录 支持扫码登录
8 participants