Skip to content

Commit

Permalink
Merge pull request #132 from Aguafrommars/master
Browse files Browse the repository at this point in the history
3.4.0
  • Loading branch information
aguacongas authored May 6, 2023
2 parents 9ad713c + dca36f1 commit e79ad14
Show file tree
Hide file tree
Showing 19 changed files with 221 additions and 105 deletions.
2 changes: 1 addition & 1 deletion .dccache

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .github/workflows/check-dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Setup .NET Core SDK
uses: actions/[email protected]
with:
dotnet-version: '6.0.x'
dotnet-version: '7.0.x'
# Run update depencies script
- name: Update dependencies
run: ./update-dependencies.ps1
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -298,4 +298,5 @@ __pycache__/
/test/identityfirestore.json
coverage.cobertura.xml
.sonarqube/
secure-file/
secure-file/
global.json
10 changes: 5 additions & 5 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ image:
- Visual Studio 2019
environment:
GH_TOKEN:
secure: 01BiLL1kdV7X6Y7RjFyKPYwMEQr6vEpyLsGwqnRqHpMY7AyGlPdktsUH4L5A9vR6
secure: /o9VAhx5ewGmdLR9qcgFJMzBaCuzOmGlsXAHu7khUJLdQzsv4gJzLUfYDghcRPHd
access_token:
secure: yQcU3EbE3/jaIhwn6e+n76xzcQ+tGXXdIZAmA3Z8ssj5IEYPehthJkLYhhNEmw21
EmailPasswordOptions:ApiKey:
Expand All @@ -24,7 +24,7 @@ environment:
secure: h7zhWIG5sQBVM6loU77ClQ==
decrypt_secret:
secure: BDKOW5teXcJUwLqekbf6VQ==
donetsdk: 6.0.300
donetsdk: 7.0.202
init:
- cmd: git config --global core.autocrlf true
install:
Expand All @@ -37,10 +37,10 @@ install:
- sh: sudo ./dotnet-install.sh -Channel Current -Version $donetsdk -InstallDir ./dotnetsdk -NoPath
- sh: export PATH=/home/appveyor/projects/identity-firebase/dotnetsdk:$PATH
- sh: sudo apt -y install nuget
- ps: if ($isWindows) { ./dotnet-install.ps1 -Version 5.0.403 }
- cmd: pwsh ./dotnet-install.ps1 -Version 6.0.406 -InstallDir "C:\Program Files\dotnet"
- ps: dotnet tool install --global GitVersion.Tool
- ps: dotnet gitversion /l console /output buildserver
- ps: if ($isWindows) { ./dotnet-install.ps1 -Version $env:donetsdk }
- cmd: pwsh ./dotnet-install.ps1 -Version %donetsdk% -InstallDir "C:\Program Files\dotnet"
- ps: dotnet tool install --global dotnet-sonarscanner
- cmd: nuget install ReportGenerator -ExcludeVersion
- nuget install secure-file -ExcludeVersion
Expand All @@ -61,7 +61,7 @@ artifacts:
deploy:
- provider: NuGet
api_key:
secure: bvkKhXIKsDM1ThfcWTbuusND0sOBiDoJGOoD2fYijGoj4C9xx22QKfR7Y9q+j7eX
secure: L5Ol2yiygLW8nUF6j5/rwx4feonMPly+S69GjoX1ilEUklPMixlX5RW2l8FJScNK
on:
branch:
- /preview\/*/
Expand Down
4 changes: 2 additions & 2 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if ($isLinux) {
$prArgs = "-d:sonar.branch.name=$env:APPVEYOR_REPO_BRANCH"
}

dotnet sonarscanner begin /k:aguacongas_Identity.Firebase -o:aguacongas -d:sonar.host.url=https://sonarcloud.io -d:sonar.login=$env:sonarqube -d:sonar.coverageReportPaths=coverage\SonarQube.xml $prArgs -v:$env:nextversion
dotnet sonarscanner begin /k:aguacongas_Identity.Firebase -o:aguafrommars -d:sonar.host.url=https://sonarcloud.io -d:sonar.login=$env:sonarqube -d:sonar.coverageReportPaths=coverage\SonarQube.xml $prArgs -v:$env:nextversion

dotnet build -c Release

Expand All @@ -42,7 +42,7 @@ if ($isLinux) {
$merge = "$merge;$path"
}
Write-Host $merge
ReportGenerator\tools\netcoreapp3.0\ReportGenerator.exe "-reports:$merge" "-targetdir:coverage" "-reporttypes:SonarQube"
ReportGenerator\tools\net7.0\ReportGenerator.exe "-reports:$merge" "-targetdir:coverage" "-reporttypes:SonarQube"

dotnet sonarscanner end -d:sonar.login=$env:sonarqube
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<Description>Identity sample MVC application on ASP.NET Core</Description>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<UserSecretsId>Firestore.IdentitySample.Mvc</UserSecretsId>
<SonarQubeExclude>true</SonarQubeExclude>
</PropertyGroup>
Expand All @@ -16,16 +16,16 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aguacongas.Identity.Firestore" Version="3.3.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Facebook" Version="6.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="6.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Twitter" Version="6.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="6.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="6.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.5" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="6.0.0" />
<PackageReference Include="Aguacongas.Identity.Firestore" Version="3.3.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Facebook" Version="7.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="7.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Twitter" Version="7.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="7.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="7.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.5" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion samples/Firestore.IdentitySample.Mvc/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void ConfigureServices(IServiceCollection services)
.AddFirestoreStores(options =>
{
Configuration.GetSection("AuthTokenOptions").Bind(options);
})
}, emulatorHostAndPort: "127.0.0.1:8085")
.AddDefaultTokenProviders();

var twitterConsumerKey = Configuration["Authentication:Twitter:ConsumerKey"];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<Description>Identity sample MVC application on ASP.NET Core</Description>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<UserSecretsId>Aguacongas.Identity.Firebase.IntegrationTest</UserSecretsId>
<SonarQubeExclude>true</SonarQubeExclude>
</PropertyGroup>
Expand All @@ -16,16 +16,16 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aguacongas.Identity.Firebase" Version="3.3.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Facebook" Version="6.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="6.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Twitter" Version="6.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="6.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="6.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.5" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="6.0.0" />
<PackageReference Include="Aguacongas.Identity.Firebase" Version="3.3.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Facebook" Version="7.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="7.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Twitter" Version="7.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="7.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="7.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.5" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Google.Apis.Auth" Version="1.57.0" />
<PackageReference Include="Google.Apis.Auth" Version="1.60.0" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.1" />
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net462'">
Expand Down
2 changes: 1 addition & 1 deletion src/Aguacongas.Firebase/Aguacongas.Firebase.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net462'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="6.0.5" />
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="7.0.5" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="6.0.5" />
<PackageReference Include="Google.Cloud.Firestore" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="7.0.5" />
<PackageReference Include="Google.Cloud.Firestore" Version="3.3.0" />
</ItemGroup>

<ItemGroup>
Expand Down
80 changes: 51 additions & 29 deletions src/Aguacongas.Identity.Firestore/IdentityBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,80 +22,96 @@ public static class IdentityBuilderExtensions
/// <summary>
/// Adds an Firebase implementation of identity stores.
/// </summary>
/// <param name="builder">The <see cref="IdentityBuilder"/> instance this method extends.</param>
/// <param name="builder">The <see cref="IdentityBuilder" /> instance this method extends.</param>
/// <param name="configure">Action to configure AuthTokenOptions</param>
/// <param name="authFilePath">The path where to store the authentication file extracted from config.</param>
/// <param name="tableNames">Action to configure table names (Firestore Collections). If null, fallbacks to defaults <see cref="FirestoreTableNamesConfig.Defaults"/></param>
/// <returns>The <see cref="IdentityBuilder"/> instance this method extends.</returns>
public static IdentityBuilder AddFirestoreStores(this IdentityBuilder builder, Action<OAuthServiceAccountKey> configure, Action<FirestoreTableNamesConfig> tableNames = null)
/// <param name="emulatorHostAndPort">Firestore Emulator Host and Port. Connect to the emulator if a value passed, or production otherwise.</param>
/// <returns>
/// The <see cref="IdentityBuilder" /> instance this method extends.
/// </returns>
public static IdentityBuilder AddFirestoreStores(this IdentityBuilder builder, Action<OAuthServiceAccountKey> configure, string authFilePath, Action<FirestoreTableNamesConfig> tableNames = null, string emulatorHostAndPort = null)
{
UseEmulator(emulatorHostAndPort);

var services = builder.Services;
services.Configure(configure)
.AddScoped(provider =>
{
var authOptions = StoreAuthFile(provider, Path.GetTempFileName());
var client = FirestoreClient.Create();

return FirestoreDb.Create(authOptions.Value.project_id, client: client);
var authOptions = StoreAuthFile(provider, authFilePath);
return new FirestoreDbBuilder
{
ProjectId = authOptions.Value.project_id,
EmulatorDetection = Google.Api.Gax.EmulatorDetection.EmulatorOrProduction
}.Build();
});

AddStores(services, builder.UserType, builder.RoleType, ResolveFirestoreTableNamesConfig(tableNames));
return builder;
}

/// <summary>
/// Adds an Firebase implementation of identity stores.
/// </summary>
/// <param name="builder">The <see cref="IdentityBuilder" /> instance this method extends.</param>
/// <param name="builder">The <see cref="IdentityBuilder"/> instance this method extends.</param>
/// <param name="configure">Action to configure AuthTokenOptions</param>
/// <param name="authFilePath">The path where to store the authentication file extracted from config.</param>
/// <param name="tableNames">Action to configure table names (Firestore Collections). If null, fallbacks to defaults <see cref="FirestoreTableNamesConfig.Defaults"/></param>
/// <returns>
/// The <see cref="IdentityBuilder" /> instance this method extends.
/// </returns>
public static IdentityBuilder AddFirestoreStores(this IdentityBuilder builder, Action<OAuthServiceAccountKey> configure, string authFilePath, Action<FirestoreTableNamesConfig> tableNames = null)
/// <param name="emulatorHostAndPort">Firestore Emulator Host and Port. Connect to the emulator if a value passed, or production otherwise.</param>
/// <returns>The <see cref="IdentityBuilder"/> instance this method extends.</returns>
public static IdentityBuilder AddFirestoreStores(this IdentityBuilder builder, Action<OAuthServiceAccountKey> configure, Action<FirestoreTableNamesConfig> tableNames = null, string emulatorHostAndPort = null)
{
UseEmulator(emulatorHostAndPort);

var services = builder.Services;
services.Configure(configure)
.AddScoped(provider =>
{
var authOptions = StoreAuthFile(provider, authFilePath);
var client = FirestoreClient.Create();

return FirestoreDb.Create(authOptions.Value.project_id, client: client);
var authOptions = StoreAuthFile(provider, Path.GetRandomFileName());
return new FirestoreDbBuilder
{
ProjectId = authOptions.Value.project_id,
EmulatorDetection = Google.Api.Gax.EmulatorDetection.EmulatorOrProduction
}.Build();
});

AddStores(services, builder.UserType, builder.RoleType, ResolveFirestoreTableNamesConfig(tableNames));
return builder;
}

private static FirestoreTableNamesConfig ResolveFirestoreTableNamesConfig(Action<FirestoreTableNamesConfig> tableNames)
{
var tableNamesConfig = new FirestoreTableNamesConfig();
tableNames?.Invoke(tableNamesConfig);
return tableNamesConfig;
}

/// <summary>
/// Adds an Firebase implementation of identity stores.
/// </summary>
/// <param name="builder">The <see cref="IdentityBuilder" /> instance this method extends.</param>
/// <param name="projectId">The project identifier.</param>
/// <param name="tableNames">Action to configure table names (Firestore Collections). If null, fallbacks to defaults <see cref="FirestoreTableNamesConfig.Defaults"/></param>
/// <param name="emulatorHostAndPort">Firestore Emulator Host and Port. Connect to the emulator if a value passed, or production otherwise.</param>
/// <returns>
/// The <see cref="IdentityBuilder" /> instance this method extends.
/// </returns>
public static IdentityBuilder AddFirestoreStores(this IdentityBuilder builder, string projectId, Action<FirestoreTableNamesConfig> tableNames = null)
public static IdentityBuilder AddFirestoreStores(this IdentityBuilder builder, string projectId, Action<FirestoreTableNamesConfig> tableNames = null, string emulatorHostAndPort = null)
{
UseEmulator(emulatorHostAndPort);

var services = builder.Services;
services
.AddScoped(provider =>
{
var client = FirestoreClient.Create();
return FirestoreDb.Create(projectId, client: client);
return new FirestoreDbBuilder
{
ProjectId = projectId,
EmulatorDetection = Google.Api.Gax.EmulatorDetection.EmulatorOrProduction
}.Build();
});
AddStores(services, builder.UserType, builder.RoleType, ResolveFirestoreTableNamesConfig(tableNames));
return builder;
}

private static FirestoreTableNamesConfig ResolveFirestoreTableNamesConfig(Action<FirestoreTableNamesConfig> tableNames)
{
var tableNamesConfig = new FirestoreTableNamesConfig();
tableNames?.Invoke(tableNamesConfig);
return tableNamesConfig;
}

private static IOptions<OAuthServiceAccountKey> StoreAuthFile(IServiceProvider provider, string authFilePath)
{
var authOptions = provider.GetRequiredService<IOptions<OAuthServiceAccountKey>>();
Expand Down Expand Up @@ -148,7 +164,7 @@ private static TypeInfo FindGenericBaseType(Type currentType, Type genericBaseTy
while (type != null)
{
var typeInfo = type.GetTypeInfo();
var genericType = type.IsGenericType ? type: null;
var genericType = type.IsGenericType ? type : null;
if (genericType != null && genericType == genericBaseType)
{
return typeInfo;
Expand All @@ -157,5 +173,11 @@ private static TypeInfo FindGenericBaseType(Type currentType, Type genericBaseTy
}
return null;
}

private static void UseEmulator(string emulatorHostAndPort)
{
if (!string.IsNullOrEmpty(emulatorHostAndPort))
Environment.SetEnvironmentVariable("FIRESTORE_EMULATOR_HOST", emulatorHostAndPort);
}
}
}
Loading

0 comments on commit e79ad14

Please sign in to comment.