コード例 #1
0
        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}"
                    )
                );
        }
コード例 #2
0
        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;
        }
コード例 #4
0
        public PassportScope Push(IPassport passport, string name)
        {
            PassportScope parent = null;

            var parentCallContext = CallContext.LogicalGetData(Constants.Passports.KeyCurrentCallContext);
            if (parentCallContext != null)
                parent = _scopes[(string)parentCallContext];
            var currentId = Guid.NewGuid();
            var key = currentId.ToString("N");
            CallContext.LogicalSetData(Constants.Passports.KeyCurrentCallContext, key);

            var current = new PassportScope(passport, name, currentId, parent);
            lock (Lock)
            {
                _scopes[key] = current;
            }

            return current;
        }
コード例 #5
0
        public PassportScope Push(IPassport passport, string name)
        {
            PassportScope parent = null;

            var parentCallContext = CallContext.LogicalGetData(Constants.Passports.KeyCurrentCallContext);

            if (parentCallContext != null)
            {
                parent = _scopes[(string)parentCallContext];
            }
            var currentId = Guid.NewGuid();
            var key       = currentId.ToString("N");

            CallContext.LogicalSetData(Constants.Passports.KeyCurrentCallContext, key);

            var current = new PassportScope(passport, name, currentId, parent);

            lock (Lock)
            {
                _scopes[key] = current;
            }

            return(current);
        }