Skip to content

Commit e2e3ffa

Browse files
committed
Merge branch 'hkj-update-user' into hkj-auth-test
2 parents adf065d + 28129b3 commit e2e3ffa

File tree

10 files changed

+176
-13
lines changed

10 files changed

+176
-13
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Unreleased
22

3+
- [added] Implemented the `UpdateUserAsync()` API.
34
- [added] Implemented the `CreateUserAsync()` and `UserRecordArgs` APIs.
5+
6+
# v1.6.0
7+
8+
- [added] `WebpushFcmOptions` added to the `WebpushConfig` class.
49
- [added] Implemented the `GetUserByEmailAsync()` and `GetUserByPhoneNumberAsync()`
510
APIs in the `FirebaseAuth` class.
611

FirebaseAdmin/FirebaseAdmin.Tests/Messaging/MessageTest.cs

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,6 +1558,98 @@ public void ApnsInvalidCriticalSoundVolumeTooHigh()
15581558
Assert.Throws<ArgumentException>(() => message.CopyAndValidate());
15591559
}
15601560

1561+
[Fact]
1562+
public void WebpushNotificationWithLinkUrl()
1563+
{
1564+
var message = new Message()
1565+
{
1566+
Topic = "test-topic",
1567+
Webpush = new WebpushConfig()
1568+
{
1569+
Notification = new WebpushNotification()
1570+
{
1571+
Title = "title",
1572+
Body = "body",
1573+
Icon = "icon",
1574+
},
1575+
FcmOptions = new WebpushFcmOptions()
1576+
{
1577+
Link = "https://www.firebase.io/",
1578+
},
1579+
},
1580+
};
1581+
var expected = new JObject()
1582+
{
1583+
{ "topic", "test-topic" },
1584+
{
1585+
"webpush", new JObject()
1586+
{
1587+
{
1588+
"notification", new JObject()
1589+
{
1590+
{ "title", "title" },
1591+
{ "body", "body" },
1592+
{ "icon", "icon" },
1593+
}
1594+
},
1595+
{
1596+
"fcm_options", new JObject()
1597+
{
1598+
{ "link", "https://www.firebase.io/" },
1599+
}
1600+
},
1601+
}
1602+
},
1603+
};
1604+
this.AssertJsonEquals(expected, message);
1605+
}
1606+
1607+
[Fact]
1608+
public void WebpushNotificationWithInvalidHttpLinkUrl()
1609+
{
1610+
var message = new Message()
1611+
{
1612+
Topic = "test-topic",
1613+
Webpush = new WebpushConfig()
1614+
{
1615+
Notification = new WebpushNotification()
1616+
{
1617+
Title = "title",
1618+
Body = "body",
1619+
Icon = "icon",
1620+
},
1621+
FcmOptions = new WebpushFcmOptions()
1622+
{
1623+
Link = "http://www.firebase.io/",
1624+
},
1625+
},
1626+
};
1627+
Assert.Throws<ArgumentException>(() => message.CopyAndValidate());
1628+
}
1629+
1630+
[Fact]
1631+
public void WebpushNotificationWithInvalidHttpsLinkUrl()
1632+
{
1633+
var message = new Message()
1634+
{
1635+
Topic = "test-topic",
1636+
Webpush = new WebpushConfig()
1637+
{
1638+
Notification = new WebpushNotification()
1639+
{
1640+
Title = "title",
1641+
Body = "body",
1642+
Icon = "icon",
1643+
},
1644+
FcmOptions = new WebpushFcmOptions()
1645+
{
1646+
Link = "https whatever",
1647+
},
1648+
},
1649+
};
1650+
Assert.Throws<ArgumentException>(() => message.CopyAndValidate());
1651+
}
1652+
15611653
private void AssertJsonEquals(JObject expected, Message actual)
15621654
{
15631655
var json = NewtonsoftJsonSerializer.Instance.Serialize(actual.CopyAndValidate());

FirebaseAdmin/FirebaseAdmin/Auth/UserRecordArgs.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,11 @@ private void AddDeleteProvider(string provider)
378378
}
379379
}
380380

381-
internal class Optional<T>
381+
/// <summary>
382+
/// Wraps a nullable value. Used to differentiate between parameters that have not been set, and
383+
/// the parameters that have been explicitly set to null.
384+
/// </summary>
385+
private class Optional<T>
382386
{
383387
internal Optional(T value)
384388
{

FirebaseAdmin/FirebaseAdmin/FirebaseAdmin.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<Version>1.5.0</Version>
4+
<Version>1.6.0</Version>
55
<TargetFrameworks>netstandard1.5;net45</TargetFrameworks>
66
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netstandard1.5</TargetFrameworks>
77
<LangVersion>latest</LangVersion>

FirebaseAdmin/FirebaseAdmin/Messaging/ApnsConfig.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ namespace FirebaseAdmin.Messaging
2222
{
2323
/// <summary>
2424
/// Represents the APNS-specific options that can be included in a <see cref="Message"/>. Refer
25-
/// to <see href="https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/APNSOverview.html">
26-
/// APNs documentation</see> for various headers and payload fields supported by APNS.
25+
/// to <a href="https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/APNSOverview.html">
26+
/// APNs documentation</a> for various headers and payload fields supported by APNS.
2727
/// </summary>
2828
public sealed class ApnsConfig
2929
{

FirebaseAdmin/FirebaseAdmin/Messaging/Aps.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
namespace FirebaseAdmin.Messaging
2222
{
2323
/// <summary>
24-
/// Represents the <see href="https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html">
25-
/// aps dictionary</see> that is part of every APNs message.
24+
/// Represents the <a href="https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html">
25+
/// aps dictionary</a> that is part of every APNs message.
2626
/// </summary>
2727
public sealed class Aps
2828
{

FirebaseAdmin/FirebaseAdmin/Messaging/ApsAlert.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
namespace FirebaseAdmin.Messaging
2121
{
2222
/// <summary>
23-
/// Represents the <see href="https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html#//apple_ref/doc/uid/TP40008194-CH17-SW5">
24-
/// alert property</see> that can be included in the <c>aps</c> dictionary of an APNs
23+
/// Represents the <a href="https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html#//apple_ref/doc/uid/TP40008194-CH17-SW5">
24+
/// alert property</a> that can be included in the <c>aps</c> dictionary of an APNs
2525
/// payload.
2626
/// </summary>
2727
public sealed class ApsAlert

FirebaseAdmin/FirebaseAdmin/Messaging/WebpushConfig.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ public sealed class WebpushConfig
2525
{
2626
/// <summary>
2727
/// Gets or sets the Webpush HTTP headers. Refer
28-
/// <see href="https://tools.ietf.org/html/rfc8030#section-5">
29-
/// Webpush specification</see> for supported headers.
28+
/// <a href="https://tools.ietf.org/html/rfc8030#section-5">
29+
/// Webpush specification</a> for supported headers.
3030
/// </summary>
3131
[JsonProperty("headers")]
3232
public IReadOnlyDictionary<string, string> Headers { get; set; }
@@ -39,11 +39,17 @@ public sealed class WebpushConfig
3939
public IReadOnlyDictionary<string, string> Data { get; set; }
4040

4141
/// <summary>
42-
/// Gets or sets the Webpush notification that will be included in the message.
42+
/// Gets or sets the Webpush notification included in the message.
4343
/// </summary>
4444
[JsonProperty("notification")]
4545
public WebpushNotification Notification { get; set; }
4646

47+
/// <summary>
48+
/// Gets or sets the Webpush options included in the message.
49+
/// </summary>
50+
[JsonProperty("fcm_options")]
51+
public WebpushFcmOptions FcmOptions { get; set; }
52+
4753
/// <summary>
4854
/// Copies this Webpush config, and validates the content of it to ensure that it can be
4955
/// serialized into the JSON format expected by the FCM service.
@@ -55,6 +61,7 @@ internal WebpushConfig CopyAndValidate()
5561
Headers = this.Headers?.Copy(),
5662
Data = this.Data?.Copy(),
5763
Notification = this.Notification?.CopyAndValidate(),
64+
FcmOptions = this.FcmOptions?.CopyAndValidate(),
5865
};
5966
}
6067
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright 2019, Google Inc. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
using System;
16+
using Newtonsoft.Json;
17+
18+
namespace FirebaseAdmin.Messaging
19+
{
20+
/// <summary>
21+
/// Represents the Webpush-specific notification options that can be included in a <see cref="Message"/>.
22+
/// See <a href="https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#WebpushFcmOptions">REST
23+
/// API reference</a> for a list of supported fields.
24+
/// </summary>
25+
public sealed class WebpushFcmOptions
26+
{
27+
/// <summary>
28+
/// Gets or sets the link to open when the user clicks on the notification. For all URL values, HTTPS is required.
29+
/// </summary>
30+
[JsonProperty("link")]
31+
public string Link { get; set; }
32+
33+
/// <summary>
34+
/// Copies this Webpush FCM options, and validates the content of it to ensure that it can
35+
/// be serialized into the JSON format expected by the FCM service.
36+
/// </summary>
37+
internal WebpushFcmOptions CopyAndValidate()
38+
{
39+
var copy = new WebpushFcmOptions()
40+
{
41+
Link = this.Link,
42+
};
43+
44+
if (copy.Link != null)
45+
{
46+
if (!Uri.IsWellFormedUriString(copy.Link, UriKind.Absolute) || !copy.Link.StartsWith("https"))
47+
{
48+
throw new ArgumentException("The link options should be a valid https url.");
49+
}
50+
}
51+
52+
return copy;
53+
}
54+
}
55+
}

FirebaseAdmin/FirebaseAdmin/Messaging/WebpushNotification.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ namespace FirebaseAdmin.Messaging
2323
/// <summary>
2424
/// Represents the Webpush-specific notification options that can be included in a
2525
/// <see cref="Message"/>. Supports most standard options defined in the
26-
/// <see href="https://developer.mozilla.org/en-US/docs/Web/API/notification/Notification">
27-
/// Web Notification specification</see>.
26+
/// <a href="https://developer.mozilla.org/en-US/docs/Web/API/notification/Notification">
27+
/// Web Notification specification</a>.
2828
/// </summary>
2929
public sealed class WebpushNotification
3030
{

0 commit comments

Comments
 (0)