public void Should_Create_Request_Params() { const string expectedQuery = "domain=telegrampassport" + "&bot_id=123" + "&scope=%7B%22data%22%3A%5B%5D%2C%22v%22%3A1%7D" + "&public_key=PUB%20KEY" + "&nonce=%2FNonce%21%2F"; AuthorizationRequestParameters requestParameters = new AuthorizationRequestParameters( 123, "PUB KEY", "/Nonce!/", new PassportScope(new IPassportScopeElement[0]) ); Assert.Equal(123, requestParameters.BotId); Assert.Equal("PUB KEY", requestParameters.PublicKey); Assert.Equal("/Nonce!/", requestParameters.Nonce); Assert.NotNull(requestParameters.PassportScope); Assert.Equal(1, requestParameters.PassportScope.V); Assert.Empty(requestParameters.PassportScope.Data); Assert.Equal(expectedQuery, requestParameters.Query); Assert.Equal("tg:resolve?" + expectedQuery, requestParameters.AndroidUri); Assert.Equal("tg://resolve?" + expectedQuery, requestParameters.Uri); Assert.Equal("tg://resolve?" + expectedQuery, requestParameters.ToString()); }
static async Task SendAuthorizationRequestAsync(int userId) { PassportScope scope = new PassportScope(new[] { new PassportScopeElementOne(PassportEnums.Scope.Address), new PassportScopeElementOne(PassportEnums.Scope.PhoneNumber), }); AuthorizationRequestParameters authReq = new AuthorizationRequestParameters( botId: _botClient.BotId, publicKey: PublicKey, nonce: "Test nonce for this demo", scope: scope ); await _botClient.SendTextMessageAsync( userId, "Share your *residential address* and *phone number* with bot using Telegram Passport.\n\n" + "1. Click inline button\n" + "2. Open link in browser so it redirects you to Telegram Passport\n" + "3. Authorize bot to access the info", ParseMode.Markdown, replyMarkup : (InlineKeyboardMarkup)InlineKeyboardButton.WithUrl( "Share via Passport", $"https://telegrambots.github.io/Telegram.Bot.Extensions.Passport/redirect.html?{authReq.Query}" ) ); }
public async Task Should_set_error_unspecified() { AuthorizationRequestParameters authReq = _classFixture.AuthorizationRequestParameters; Message passportMessage = _classFixture.Message; PassportElementError[] errors = { new PassportElementErrorUnspecified( PassportEnums.Scope.BankStatement, passportMessage.PassportData.Data.Single().Hash, "Address is NOT mentioned in this document" ), }; await BotClient.SetPassportDataErrorsAsync( passportMessage.From.Id, errors ); await BotClient.SendTextMessageAsync( _fixture.SupergroupChat, "An error is set on the bank statement.\n" + "You can see error message with opening the request link again.", replyMarkup : (InlineKeyboardMarkup)InlineKeyboardButton.WithUrl( "Passport Authorization Request", $"https://telegrambots.github.io/Telegram.Bot.Extensions.Passport/redirect.html?{authReq.Query}" ) ); }
public async Task Should_Generate_Auth_Link() { const string publicKey = "-----BEGIN PUBLIC KEY-----\n" + "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0VElWoQA2SK1csG2/sY/\n" + "wlssO1bjXRx+t+JlIgS6jLPCefyCAcZBv7ElcSPJQIPEXNwN2XdnTc2wEIjZ8bTg\n" + "BlBqXppj471bJeX8Mi2uAxAqOUDuvGuqth+mq7DMqol3MNH5P9FO6li7nZxI1FX3\n" + "9u2r/4H4PXRiWx13gsVQRL6Clq2jcXFHc9CvNaCQEJX95jgQFAybal216EwlnnVV\n" + "giT/TNsfFjW41XJZsHUny9k+dAfyPzqAk54cgrvjgAHJayDWjapq90Fm/+e/DVQ6\n" + "BHGkV0POQMkkBrvvhAIQu222j+03frm9b2yZrhX/qS01lyjW4VaQytGV0wlewV6B\n" + "FwIDAQAB\n" + "-----END PUBLIC KEY-----"; PassportScope scope = new PassportScope(new[] { new PassportScopeElementOneOfSeveral(new[] { new PassportScopeElementOne(PassportEnums.Scope.IdentityCard), new PassportScopeElementOne(PassportEnums.Scope.InternalPassport), }) { Selfie = true, // selfie can only be requested for documents used as proof of identity }, new PassportScopeElementOneOfSeveral(new[] { new PassportScopeElementOne(PassportEnums.Scope.UtilityBill), new PassportScopeElementOne(PassportEnums.Scope.RentalAgreement), }) { Translation = true, // Selfie = null // selfie cannot be requested for documents used as proof of address }, }); AuthorizationRequestParameters authReq = new AuthorizationRequestParameters( botId: _fixture.BotUser.Id, publicKey: publicKey, nonce: "Test nonce for id card & utility bill", scope: scope ); await BotClient.SendTextMessageAsync( _fixture.SupergroupChat, "Share your *identity card with a selfie* and " + "a *utility bill with its translation* with bot using Passport.\n\n" + "1. Click inline button\n" + "2. Open link in browser to redirect you back to Telegram passport\n" + "3. Authorize bot to access the info", ParseMode.Markdown, replyMarkup : (InlineKeyboardMarkup)InlineKeyboardButton.WithUrl( "Share via Passport", $"https://telegrambots.github.io/Telegram.Bot.Extensions.Passport/redirect.html?{authReq.Query}" ) ); Update passportUpdate = await _fixture.UpdateReceiver.GetPassportUpdate(); _classFixture.Entity = passportUpdate; }
public async Task Should_Generate_Auth_Link() { const string publicKey = "-----BEGIN PUBLIC KEY-----\n" + "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0VElWoQA2SK1csG2/sY/\n" + "wlssO1bjXRx+t+JlIgS6jLPCefyCAcZBv7ElcSPJQIPEXNwN2XdnTc2wEIjZ8bTg\n" + "BlBqXppj471bJeX8Mi2uAxAqOUDuvGuqth+mq7DMqol3MNH5P9FO6li7nZxI1FX3\n" + "9u2r/4H4PXRiWx13gsVQRL6Clq2jcXFHc9CvNaCQEJX95jgQFAybal216EwlnnVV\n" + "giT/TNsfFjW41XJZsHUny9k+dAfyPzqAk54cgrvjgAHJayDWjapq90Fm/+e/DVQ6\n" + "BHGkV0POQMkkBrvvhAIQu222j+03frm9b2yZrhX/qS01lyjW4VaQytGV0wlewV6B\n" + "FwIDAQAB\n" + "-----END PUBLIC KEY-----"; PassportScope scope = new PassportScope(new[] { new PassportScopeElementOne(PassportEnums.Scope.Passport) { Selfie = true, Translation = true, }, }); AuthorizationRequestParameters authReq = new AuthorizationRequestParameters( botId: _fixture.BotUser.Id, publicKey: publicKey, nonce: "Test nonce for passport", scope: scope ); await BotClient.SendTextMessageAsync( _fixture.SupergroupChat, "Share your *passport* with its *translation* and a *selfie* using Telegram Passport.\n\n" + "1. Click inline button\n" + "2. Open link in browser to redirect you back to Telegram passport\n" + "3. Authorize bot to access the info", ParseMode.Markdown, replyMarkup : (InlineKeyboardMarkup)InlineKeyboardButton.WithUrl( "Share via Passport", $"https://telegrambots.github.io/Telegram.Bot.Extensions.Passport/redirect.html?{authReq.Query}" ) ); Update passportUpdate = await _fixture.UpdateReceiver.GetPassportUpdate(); RSA key = EncryptionKey.ReadAsRsa(); IDecrypter decrypter = new Decrypter(); Credentials credentials = decrypter.DecryptCredentials(passportUpdate.Message.PassportData.Credentials, key); Assert.Equal("Test nonce for passport", credentials.Nonce); _classFixture.AuthorizationRequestParameters = authReq; _classFixture.Credentials = credentials; _classFixture.Message = passportUpdate.Message; }
public async Task Should_Set_Errors_Passport() { AuthorizationRequestParameters authReq = _classFixture.AuthorizationRequestParameters; Credentials credentials = _classFixture.Credentials; Message passportMessage = _classFixture.Message; PassportElementError[] errors = { new PassportElementErrorDataField( PassportEnums.Scope.Passport, "document_no", credentials.SecureData.Passport.Data.DataHash, "Invalid passport number" ), new PassportElementErrorFrontSide( PassportEnums.Scope.Passport, credentials.SecureData.Passport.FrontSide.FileHash, "Document scan is redacted" ), new PassportElementErrorSelfie( PassportEnums.Scope.Passport, credentials.SecureData.Passport.Selfie.FileHash, "Take a selfie without glasses" ), new PassportElementErrorTranslationFile( PassportEnums.Scope.Passport, credentials.SecureData.Passport.Translation[0].FileHash, "Document photo is blury" ), }; await BotClient.SetPassportDataErrorsAsync( passportMessage.From.Id, errors ); await BotClient.SendTextMessageAsync( _fixture.SupergroupChat, "Errors are set on all passport data and documents.\n" + "You can see error message with opening the request link again.", replyMarkup : (InlineKeyboardMarkup)InlineKeyboardButton.WithUrl( "Passport Authorization Request", $"https://telegrambots.github.io/Telegram.Bot.Extensions.Passport/redirect.html?{authReq.Query}" ) ); }
public async Task Should_set_errors_for_passport_registration() { AuthorizationRequestParameters authReq = _classFixture.AuthorizationRequestParameters; Credentials credentials = _classFixture.Credentials; Message passportMessage = _classFixture.Message; PassportElementError[] errors = { new PassportElementErrorFiles( PassportEnums.Scope.PassportRegistration, credentials.SecureData.PassportRegistration.Files.Select(fc => fc.FileHash), "Uploaded files are blury" ), new PassportElementErrorFile( PassportEnums.Scope.PassportRegistration, credentials.SecureData.PassportRegistration.Files[1].FileHash, "This second file is invalid too" ), new PassportElementErrorTranslationFiles( PassportEnums.Scope.PassportRegistration, credentials.SecureData.PassportRegistration.Translation.Select(fc => fc.FileHash), "Translations are no good" ), }; await BotClient.SetPassportDataErrorsAsync( passportMessage.From.Id, errors ); await BotClient.SendTextMessageAsync( _fixture.SupergroupChat, "Errors are set on all the files for passport registration document.\n" + "You can see error message with opening the request link again.", replyMarkup : (InlineKeyboardMarkup)InlineKeyboardButton.WithUrl( "Passport Authorization Request", $"https://telegrambots.github.io/Telegram.Bot.Extensions.Passport/redirect.html?{authReq.Query}" ) ); }