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

2fa feature #17

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 12 additions & 25 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,50 +1,37 @@
name: CI
on: [push, pull_request]

env:
NUGET_URL: https://dist.nuget.org/win-x86-commandline/v5.4.0/nuget.exe
jobs:
linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Download latest NuGet
run: wget $NUGET_URL

- name: Install Dependencies
run: mono nuget.exe restore src/TgSharp.sln
run: dotnet restore src

- name: Build Project
run: xbuild src/TgSharp.Core/TgSharp.Core.csproj
run: dotnet build src

macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2

- name: Download latest NuGet
run: curl -o nuget.exe $NUGET_URL

- name: Install Dependencies
run: mono nuget.exe restore src/TgSharp.sln
run: dotnet restore src

- name: Build Project
run: MSBuild src/TgSharp.Core/TgSharp.Core.csproj
run: dotnet build src

windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2

- name: Download Nuget.exe
run: Invoke-WebRequest -OutFile Nuget.exe $Env:NUGET_URL


- name: Install Dependencies
run: ./Nuget.exe restore src/TgSharp.sln

- name: setup-msbuild
uses: microsoft/setup-msbuild@v1

run: dotnet restore src

- name: Build Project
run: MSBuild src/TgSharp.sln
run: dotnet build src

10 changes: 5 additions & 5 deletions .github/workflows/nugetUpload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ jobs:
run: Invoke-WebRequest -OutFile Nuget.exe $Env:NUGET_URL

- name: Install Dependencies
run: ./Nuget.exe restore src/TgSharp.sln
run: dotnet restore

- name: setup-msbuild
uses: microsoft/setup-msbuild@v1
- name: Build
run: dotnet build

- name: Build & Upload Package
- name: Package && Upload
run: |
$date = get-date -format "yyyyMMdd-HHmm"
$hash = & git rev-parse --short HEAD
Expand All @@ -32,7 +32,7 @@ jobs:
$version = "$baseVersion--date$date.git-$hash"
}

./Nuget.exe pack src/TgSharp.Core/TgSharp.Core.csproj -Version $version -Build -Properties Configuration=Release
./Nuget.exe pack src/TgSharp.Core/TgSharp.Core.csproj -Version $version -Properties Configuration=Release
If ($Env:GITHUB_REF -eq 'refs/heads/master' -OR $Env:GITHUB_REF.StartsWith($tagPrefix)) {
If ('${{ secrets.NUGET_API_KEY }}' -ne '') {
./Nuget.exe push "TgSharp.$version.nupkg" ${{secrets.NUGET_API_KEY}} -Source https://api.nuget.org/v3/index.json
Expand Down
36 changes: 0 additions & 36 deletions src/TgSharp.Core/Properties/AssemblyInfo.cs

This file was deleted.

24 changes: 21 additions & 3 deletions src/TgSharp.Core/TelegramClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public async Task<string> SendCodeRequestAsync(string phoneNumber, CancellationT
return request.Response.PhoneCodeHash;
}

public async Task<TLUser> MakeAuthAsync(string phoneNumber, string phoneCodeHash, string code, string firstName = "", string lastName = "", CancellationToken token = default(CancellationToken))
public async Task<TLUser> MakeAuthAsync(string phoneNumber, string phoneCodeHash, string code, string password = "", string firstName = "", string lastName = "", CancellationToken token = default(CancellationToken))
{
if (String.IsNullOrWhiteSpace(phoneNumber))
throw new ArgumentNullException(nameof(phoneNumber));
Expand All @@ -222,14 +222,32 @@ public async Task<TLUser> MakeAuthAsync(string phoneNumber, string phoneCodeHash
throw new ArgumentNullException(nameof(code));

var request = new TLRequestSignIn() { PhoneNumber = phoneNumber, PhoneCodeHash = phoneCodeHash, PhoneCode = code };
TLRequestCheckPassword requestCheckPassword = null;

await RequestWithDcMigration(request, token).ConfigureAwait(false);
try
{
await RequestWithDcMigration(request, token).ConfigureAwait(false);
}
catch (CloudPasswordNeededException ex)
{
if (password != "")
{
requestCheckPassword = new TLRequestCheckPassword { Password = await SRPHelper.CheckPassword(this, password, token) };
await RequestWithDcMigration(requestCheckPassword, token).ConfigureAwait(false);
}
else throw ex;
}

if (request.Response is TLAuthorization)
if (requestCheckPassword == null && request.Response is TLAuthorization)
{
OnUserAuthenticated(((TLUser)((TLAuthorization)request.Response).User));
return ((TLUser)((TLAuthorization)request.Response).User);
}
else if (requestCheckPassword != null && requestCheckPassword.Response is TLAuthorization)
{
OnUserAuthenticated(((TLUser)((TLAuthorization)requestCheckPassword.Response).User));
return ((TLUser)((TLAuthorization)requestCheckPassword.Response).User);
}
else
{
var signUpRequest = new TLRequestSignUp() { PhoneNumber = phoneNumber, PhoneCodeHash = phoneCodeHash, FirstName = firstName, LastName = lastName };
Expand Down
101 changes: 9 additions & 92 deletions src/TgSharp.Core/TgSharp.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,98 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{400D2544-1CC6-4D8A-A62C-2292D9947A16}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>TgSharp.Core</RootNamespace>
<AssemblyName>TgSharp.Core</AssemblyName>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Auth\Authenticator.cs" />
<Compile Include="Auth\Step1_PQRequest.cs" />
<Compile Include="Auth\Step2_DHExchange.cs" />
<Compile Include="Auth\Step3_CompleteDHExchange.cs" />
<Compile Include="DataCenterIPVersion.cs" />
<Compile Include="Exceptions\CloudPasswordNeededException.cs" />
<Compile Include="Exceptions\InvalidPhoneCodeException.cs" />
<Compile Include="Exceptions\MissingApiConfigurationException.cs" />
<Compile Include="MTProto\Crypto\AES.cs" />
<Compile Include="MTProto\Crypto\AuthKey.cs" />
<Compile Include="MTProto\Crypto\BigInteger.cs" />
<Compile Include="MTProto\Crypto\Crc32.cs" />
<Compile Include="MTProto\Crypto\Factorizator.cs" />
<Compile Include="MTProto\Crypto\MD5Digest.cs" />
<Compile Include="MTProto\Crypto\RSA.cs" />
<Compile Include="MTProto\Crypto\Salt.cs" />
<Compile Include="MTProto\Serializers.cs" />
<Compile Include="Network\Exceptions\DataCenterMigrationException.cs" />
<Compile Include="Network\Exceptions\FileMigrationException.cs" />
<Compile Include="Network\Exceptions\FloodException.cs" />
<Compile Include="Network\MtProtoPlainSender.cs" />
<Compile Include="Network\MtProtoSender.cs" />
<Compile Include="Network\Exceptions\NetworkMigrationException.cs" />
<Compile Include="Network\Exceptions\PhoneMigrationException.cs" />
<Compile Include="Network\TcpMessage.cs" />
<Compile Include="Network\TcpTransport.cs" />
<Compile Include="Network\Exceptions\UserMigrationException.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Network\Requests\AckRequest.cs" />
<Compile Include="Network\Requests\PingRequest.cs" />
<Compile Include="Utils\UploadHelper.cs" />
<Compile Include="Session.cs" />
<Compile Include="TelegramClient.cs" />
<Compile Include="Utils\Helpers.cs" />
<Compile Include="DataCenter.cs" />
</ItemGroup>

<ItemGroup>
<None Include="packages.config" />
<PackageReference Include="Portable.BouncyCastle" Version="1.8.6.7" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\TgSharp.TL\TgSharp.TL.csproj">
<Project>{d6144517-91d2-4880-86df-e9ff5d7f383a}</Project>
<Name>TeleSharp.TL</Name>
</ProjectReference>
<ProjectReference Include="..\TgSharp.TL\TgSharp.TL.csproj" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

</Project>
40 changes: 24 additions & 16 deletions src/TgSharp.Core/TgSharp.Core.nuspec
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>TgSharp</id>
<version>0.1</version>
<title>Telegram client library implemented in C#</title>
<authors>Ilya P</authors>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>TgSharp</id>
<version>0.1</version>
<title>Telegram client library implemented in C#</title>
<authors>Ilya P</authors>
<owners>aarani, knocte</owners>
<projectUrl>https://github.com/nblockchain/TgSharp/</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Unofficial Telegram (http://telegram.org) client library implemented in C#.
<license type="expression">MIT</license>
<projectUrl>https://github.com/nblockchain/TgSharp/</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>
Unofficial Telegram (http://telegram.org) client library implemented in C#.

It's a perfect fit for any developer who would like to send data directly to Telegram users or write own custom Telegram client.</description>
<tags>telegram client, telegram API</tags>
<copyright>Copyright 2015-2020</copyright>
</metadata>
<files>
<file src="bin\Release\TgSharp.TL.dll" target="lib\net46\TgSharp.TL.dll" />
</files>
It's a perfect fit for any developer who would like to send data directly to Telegram users or write own custom Telegram client.
</description>
<tags>telegram client, telegram API</tags>
<copyright>Copyright 2015-2020</copyright>
<dependencies>
<group targetFramework="netstandard2.0">
<dependency id="Portable.BouncyCastle" version="1.8.6.7" />
</group>
</dependencies>
</metadata>
<files>
<file src="bin\Release\netstandard2.0\TgSharp.TL.dll" target="lib\netstandard2.0\TgSharp.TL.dll" />
</files>
</package>