Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ matrix:
script:
- dotnet build FirebaseAdmin/FirebaseAdmin
- dotnet build FirebaseAdmin/FirebaseAdmin.Snippets
- dotnet build FirebaseAdmin/FirebaseAdmin.IntegrationTests
- dotnet test FirebaseAdmin/FirebaseAdmin.Tests
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>

<IsPackable>false</IsPackable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<CodeAnalysisRuleSet>../../stylecop_test.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

<ItemGroup>
Expand All @@ -12,6 +13,9 @@
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.1-beta.61">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
36 changes: 19 additions & 17 deletions FirebaseAdmin/FirebaseAdmin.IntegrationTests/FirebaseAuthTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Xunit;
using FirebaseAdmin;
using FirebaseAdmin.Auth;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Util;
using Xunit;

namespace FirebaseAdmin.IntegrationTests
{
public class FirebaseAuthTest
{
private const string VerifyCustomTokenUrl =
private const string VerifyCustomTokenUrl =
"https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyCustomToken";

public FirebaseAuthTest()
{
IntegrationTestUtils.EnsureDefaultApp();
}

[Fact]
public async Task CreateCustomToken()
{
Expand All @@ -50,9 +50,9 @@ public async Task CreateCustomTokenWithClaims()
{
var developerClaims = new Dictionary<string, object>()
{
{"admin", true},
{"package", "gold"},
{"magicNumber", 42L},
{ "admin", true },
{ "package", "gold" },
{ "magicNumber", 42L },
};
var customToken = await FirebaseAuth.DefaultInstance.CreateCustomTokenAsync(
"testuser", developerClaims);
Expand All @@ -72,13 +72,14 @@ public async Task CreateCustomTokenWithClaims()
public async Task CreateCustomTokenWithoutServiceAccount()
{
var googleCred = FirebaseApp.DefaultInstance.Options.Credential;
var serviceAcct = (ServiceAccountCredential) googleCred.UnderlyingCredential;
var token = await ((ITokenAccess) googleCred).GetAccessTokenForRequestAsync();
var app = FirebaseApp.Create(new AppOptions()
{
Credential = GoogleCredential.FromAccessToken(token),
ServiceAccountId = serviceAcct.Id,
}, "IAMSignApp");
var serviceAcct = (ServiceAccountCredential)googleCred.UnderlyingCredential;
var token = await ((ITokenAccess)googleCred).GetAccessTokenForRequestAsync();
var app = FirebaseApp.Create(
new AppOptions()
{
Credential = GoogleCredential.FromAccessToken(token),
ServiceAccountId = serviceAcct.Id,
}, "IAMSignApp");
try
{
var customToken = await FirebaseAuth.GetAuth(app).CreateCustomTokenAsync(
Expand All @@ -98,7 +99,7 @@ public async Task SetCustomUserClaims()
{
var customClaims = new Dictionary<string, object>()
{
{"admin", true}
{ "admin", true },
};

await FirebaseAuth.DefaultInstance.SetCustomUserClaimsAsync("testuser", customClaims);
Expand Down Expand Up @@ -126,12 +127,13 @@ private static async Task<string> SignInWithCustomTokenAsync(string customToken)
var rb = new Google.Apis.Requests.RequestBuilder()
{
Method = Google.Apis.Http.HttpConsts.Post,
BaseUri = new Uri(VerifyCustomTokenUrl),
BaseUri = new Uri(VerifyCustomTokenUrl),
};
rb.AddParameter(RequestParameterType.Query, "key", IntegrationTestUtils.GetApiKey());
var request = rb.CreateRequest();
var jsonSerializer = Google.Apis.Json.NewtonsoftJsonSerializer.Instance;
var payload = jsonSerializer.Serialize(new SignInRequest{
var payload = jsonSerializer.Serialize(new SignInRequest
{
CustomToken = customToken,
ReturnSecureToken = true,
});
Expand Down Expand Up @@ -159,6 +161,6 @@ internal class SignInRequest
internal class SignInResponse
{
[Newtonsoft.Json.JsonProperty("idToken")]
public String IdToken { get; set; }
public string IdToken { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ internal static class IntegrationTestUtils
private const string ServiceAccountFile = "./resources/integration_cert.json";
private const string ApiKeyFile = "./resources/integration_apikey.txt";

private static readonly Lazy<FirebaseApp> DefaultFirebaseApp = new Lazy<FirebaseApp>(() => {
var options = new AppOptions()
private static readonly Lazy<FirebaseApp> DefaultFirebaseApp = new Lazy<FirebaseApp>(
() =>
{
Credential = GoogleCredential.FromFile(ServiceAccountFile),
};
return FirebaseApp.Create(options);
}, true);
var options = new AppOptions()
{
Credential = GoogleCredential.FromFile(ServiceAccountFile),
};
return FirebaseApp.Create(options);
}, true);

public static FirebaseApp EnsureDefaultApp()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<IsPackable>false</IsPackable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<CodeAnalysisRuleSet>../../stylecop_test.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

<ItemGroup>
Expand All @@ -11,6 +13,9 @@

<ItemGroup>
<ProjectReference Include="..\FirebaseAdmin\FirebaseAdmin.csproj" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.1-beta.61">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

</Project>
16 changes: 8 additions & 8 deletions FirebaseAdmin/FirebaseAdmin.Snippets/FirebaseAppSnippets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

namespace FirebaseAdmin.Snippets
{
class FirebaseAppSnippets
internal class FirebaseAppSnippets
{
static void InitSdkWithServiceAccount()
internal static void InitSdkWithServiceAccount()
{
// [START initialize_sdk_with_service_account]
FirebaseApp.Create(new AppOptions()
Expand All @@ -33,7 +33,7 @@ static void InitSdkWithServiceAccount()
// [END initialize_sdk_with_service_account]
}

static void InitSdkWithApplicationDefault()
internal static void InitSdkWithApplicationDefault()
{
// [START initialize_sdk_with_application_default]
FirebaseApp.Create(new AppOptions()
Expand All @@ -43,7 +43,7 @@ static void InitSdkWithApplicationDefault()
// [END initialize_sdk_with_application_default]
}

static void InitSdkWithRefreshToken()
internal static void InitSdkWithRefreshToken()
{
// [START initialize_sdk_with_refresh_token]
FirebaseApp.Create(new AppOptions()
Expand All @@ -53,14 +53,14 @@ static void InitSdkWithRefreshToken()
// [END initialize_sdk_with_refresh_token]
}

static void InitSdkWithDefaultConfig()
internal static void InitSdkWithDefaultConfig()
{
// [START initialize_sdk_with_default_config]
FirebaseApp.Create();
// [END initialize_sdk_with_default_config]
}

static void InitDefaultApp()
internal static void InitDefaultApp()
{
// [START access_services_default]
// Initialize the default app
Expand All @@ -78,7 +78,7 @@ static void InitDefaultApp()
// [END access_services_default]
}

static void InitCustomApp()
internal static void InitCustomApp()
{
var defaultOptions = new AppOptions()
{
Expand Down Expand Up @@ -107,7 +107,7 @@ static void InitCustomApp()
// [END access_services_nondefault]
}

static void InitWithServiceAccountId()
internal static void InitWithServiceAccountId()
{
// [START initialize_sdk_with_service_account_id]
FirebaseApp.Create(new AppOptions()
Expand Down
8 changes: 4 additions & 4 deletions FirebaseAdmin/FirebaseAdmin.Snippets/FirebaseAuthSnippets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

namespace FirebaseAdmin.Snippets
{
class FirebaseAuthSnippets
internal class FirebaseAuthSnippets
{
static async Task CreateCustomTokenAsync()
internal static async Task CreateCustomTokenAsync()
{
// [START custom_token]
var uid = "some-uid";
Expand All @@ -32,7 +32,7 @@ static async Task CreateCustomTokenAsync()
Console.WriteLine("Created custom token: {0}", customToken);
}

static async Task CreateCustomTokenWithClaimsAsync()
internal static async Task CreateCustomTokenWithClaimsAsync()
{
// [START custom_token_with_claims]
var uid = "some-uid";
Expand All @@ -48,7 +48,7 @@ static async Task CreateCustomTokenWithClaimsAsync()
Console.WriteLine("Created custom token: {0}", customToken);
}

static async Task VeridyIdTokenAsync(string idToken)
internal static async Task VeridyIdTokenAsync(string idToken)
{
// [START verify_id_token]
FirebaseToken decodedToken = await FirebaseAuth.DefaultInstance
Expand Down
Loading