Skip to content
This repository was archived by the owner on May 15, 2024. It is now read-only.

Commit 38814da

Browse files
Add id_token property (#1192)
* Add id_token property Apple doesn't return an access token on iOS native sign in, but it does return id_token as a JWT. This adds a property to the auth result to access IdToken easily and then changes the sample to try and use IdToken if AccessToken is null. * Update docs Co-authored-by: James Montemagno <[email protected]>
1 parent 2bcb47d commit 38814da

File tree

10 files changed

+41
-14
lines changed

10 files changed

+41
-14
lines changed

Samples/Samples/View/WebAuthenticatorPage.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
<Button Text="Facebook" Command="{Binding FacebookCommand}" BackgroundColor="#3b5998" TextColor="White" />
2020
<Button Text="Apple" Command="{Binding AppleCommand}" BackgroundColor="Black" TextColor="White" />
2121

22-
<Label Text="Access Token:" FontAttributes="Bold" Margin="12,12,12,0" />
23-
<Label Text="{Binding AccessToken}" TextColor="Red" FontAttributes="Italic" />
22+
<Label Text="Auth Token:" FontAttributes="Bold" Margin="12,12,12,0" />
23+
<Label Text="{Binding AuthToken}" TextColor="Red" FontAttributes="Italic" />
2424
</StackLayout>
2525
</ScrollView>
2626
</StackLayout>

Samples/Samples/ViewModel/WebAuthenticatorViewModel.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public WebAuthenticatorViewModel()
2828

2929
string accessToken = string.Empty;
3030

31-
public string AccessToken
31+
public string AuthToken
3232
{
3333
get => accessToken;
3434
set => SetProperty(ref accessToken, value);
@@ -54,11 +54,11 @@ async Task OnAuthenticate(string scheme)
5454
r = await WebAuthenticator.AuthenticateAsync(authUrl, callbackUrl);
5555
}
5656

57-
AccessToken = r?.AccessToken;
57+
AuthToken = r?.AccessToken ?? r?.IdToken;
5858
}
5959
catch (Exception ex)
6060
{
61-
AccessToken = string.Empty;
61+
AuthToken = string.Empty;
6262
await DisplayAlertAsync($"Failed: {ex.Message}");
6363
}
6464
}

Xamarin.Essentials/WebAuthenticator/WebAuthenticatorResult.shared.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ public string AccessToken
4646
public string RefreshToken
4747
=> Get("refresh_token");
4848

49+
public string IdToken
50+
=> Get("id_token");
51+
4952
public DateTimeOffset? RefreshTokenExpiresIn
5053
{
5154
get

docs/en/FrameworksIndex/xamarin-essentials-android.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,7 @@
879879
<Member Id="M:Xamarin.Essentials.WebAuthenticatorResult.Put(System.String,System.String)" />
880880
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.AccessToken" />
881881
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.ExpiresIn" />
882+
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.IdToken" />
882883
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.Properties" />
883884
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.RefreshToken" />
884885
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.RefreshTokenExpiresIn" />

docs/en/FrameworksIndex/xamarin-essentials-ios.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,7 @@
874874
<Member Id="M:Xamarin.Essentials.WebAuthenticatorResult.Put(System.String,System.String)" />
875875
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.AccessToken" />
876876
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.ExpiresIn" />
877+
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.IdToken" />
877878
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.Properties" />
878879
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.RefreshToken" />
879880
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.RefreshTokenExpiresIn" />

docs/en/FrameworksIndex/xamarin-essentials-tvos.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,7 @@
836836
<Member Id="M:Xamarin.Essentials.WebAuthenticatorResult.Put(System.String,System.String)" />
837837
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.AccessToken" />
838838
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.ExpiresIn" />
839+
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.IdToken" />
839840
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.Properties" />
840841
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.RefreshToken" />
841842
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.RefreshTokenExpiresIn" />

docs/en/FrameworksIndex/xamarin-essentials-uwp.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,7 @@
835835
<Member Id="M:Xamarin.Essentials.WebAuthenticatorResult.Put(System.String,System.String)" />
836836
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.AccessToken" />
837837
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.ExpiresIn" />
838+
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.IdToken" />
838839
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.Properties" />
839840
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.RefreshToken" />
840841
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.RefreshTokenExpiresIn" />

docs/en/FrameworksIndex/xamarin-essentials-watchos.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,7 @@
845845
<Member Id="M:Xamarin.Essentials.WebAuthenticatorResult.Put(System.String,System.String)" />
846846
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.AccessToken" />
847847
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.ExpiresIn" />
848+
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.IdToken" />
848849
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.Properties" />
849850
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.RefreshToken" />
850851
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.RefreshTokenExpiresIn" />

docs/en/FrameworksIndex/xamarin-essentials.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,7 @@
809809
<Member Id="M:Xamarin.Essentials.WebAuthenticatorResult.Put(System.String,System.String)" />
810810
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.AccessToken" />
811811
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.ExpiresIn" />
812+
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.IdToken" />
812813
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.Properties" />
813814
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.RefreshToken" />
814815
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.RefreshTokenExpiresIn" />

docs/en/Xamarin.Essentials/WebAuthenticatorResult.xml

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<Parameters />
2828
<Docs>
2929
<summary>
30-
<para />
30+
<para></para>
3131
</summary>
3232
<remarks>To be added.</remarks>
3333
</Docs>
@@ -127,13 +127,31 @@
127127
<param name="key">Key from the callback URI's query string.</param>
128128
<summary>Gets a value for a given key from the dictionary.</summary>
129129
<returns>
130-
<para />
130+
<para></para>
131131
</returns>
132132
<remarks>
133-
<para />
133+
<para></para>
134134
</remarks>
135135
</Docs>
136136
</Member>
137+
<Member MemberName="IdToken">
138+
<MemberSignature Language="C#" Value="public string IdToken { get; }" />
139+
<MemberSignature Language="ILAsm" Value=".property instance string IdToken" />
140+
<MemberSignature Language="DocId" Value="P:Xamarin.Essentials.WebAuthenticatorResult.IdToken" />
141+
<MemberType>Property</MemberType>
142+
<AssemblyInfo>
143+
<AssemblyName>Xamarin.Essentials</AssemblyName>
144+
<AssemblyVersion>1.0.0.0</AssemblyVersion>
145+
</AssemblyInfo>
146+
<ReturnValue>
147+
<ReturnType>System.String</ReturnType>
148+
</ReturnValue>
149+
<Docs>
150+
<summary>The value for the `id_token` key.</summary>
151+
<value>The value for the `id_token` key.</value>
152+
<remarks>Apple doesn't return an access token on iOS native sign in, but it does return id_token as a JWT.</remarks>
153+
</Docs>
154+
</Member>
137155
<Member MemberName="Properties">
138156
<MemberSignature Language="C#" Value="public System.Collections.Generic.Dictionary&lt;string,string&gt; Properties { get; set; }" />
139157
<MemberSignature Language="ILAsm" Value=".property instance class System.Collections.Generic.Dictionary`2&lt;string, string&gt; Properties" />
@@ -149,10 +167,10 @@
149167
<Docs>
150168
<summary>The dictionary of key/value pairs parsed form the callback URI's querystring.</summary>
151169
<value>
152-
<para />
170+
<para></para>
153171
</value>
154172
<remarks>
155-
<para />
173+
<para></para>
156174
</remarks>
157175
</Docs>
158176
</Member>
@@ -174,14 +192,14 @@
174192
</Parameters>
175193
<Docs>
176194
<param name="key">
177-
<para />
195+
<para></para>
178196
</param>
179197
<param name="value">
180-
<para />
198+
<para></para>
181199
</param>
182200
<summary>Puts a key/value pair into the dictionary.</summary>
183201
<remarks>
184-
<para />
202+
<para></para>
185203
</remarks>
186204
</Docs>
187205
</Member>
@@ -201,7 +219,7 @@
201219
<summary>The value for the `refresh_token` key.</summary>
202220
<value>Refresh Token parsed from the callback URI refresh_token parameter.</value>
203221
<remarks>
204-
<para />
222+
<para></para>
205223
</remarks>
206224
</Docs>
207225
</Member>

0 commit comments

Comments
 (0)