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

Commit

Permalink
Add id_token property (#1192)
Browse files Browse the repository at this point in the history
* 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 <james.montemagno@gmail.com>
  • Loading branch information
Redth and jamesmontemagno authored Mar 26, 2020
1 parent 2bcb47d commit 38814da
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Samples/Samples/View/WebAuthenticatorPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
<Button Text="Facebook" Command="{Binding FacebookCommand}" BackgroundColor="#3b5998" TextColor="White" />
<Button Text="Apple" Command="{Binding AppleCommand}" BackgroundColor="Black" TextColor="White" />

<Label Text="Access Token:" FontAttributes="Bold" Margin="12,12,12,0" />
<Label Text="{Binding AccessToken}" TextColor="Red" FontAttributes="Italic" />
<Label Text="Auth Token:" FontAttributes="Bold" Margin="12,12,12,0" />
<Label Text="{Binding AuthToken}" TextColor="Red" FontAttributes="Italic" />
</StackLayout>
</ScrollView>
</StackLayout>
Expand Down
6 changes: 3 additions & 3 deletions Samples/Samples/ViewModel/WebAuthenticatorViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public WebAuthenticatorViewModel()

string accessToken = string.Empty;

public string AccessToken
public string AuthToken
{
get => accessToken;
set => SetProperty(ref accessToken, value);
Expand All @@ -54,11 +54,11 @@ async Task OnAuthenticate(string scheme)
r = await WebAuthenticator.AuthenticateAsync(authUrl, callbackUrl);
}

AccessToken = r?.AccessToken;
AuthToken = r?.AccessToken ?? r?.IdToken;
}
catch (Exception ex)
{
AccessToken = string.Empty;
AuthToken = string.Empty;
await DisplayAlertAsync($"Failed: {ex.Message}");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public string AccessToken
public string RefreshToken
=> Get("refresh_token");

public string IdToken
=> Get("id_token");

public DateTimeOffset? RefreshTokenExpiresIn
{
get
Expand Down
1 change: 1 addition & 0 deletions docs/en/FrameworksIndex/xamarin-essentials-android.xml
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,7 @@
<Member Id="M:Xamarin.Essentials.WebAuthenticatorResult.Put(System.String,System.String)" />
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.AccessToken" />
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.ExpiresIn" />
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.IdToken" />
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.Properties" />
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.RefreshToken" />
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.RefreshTokenExpiresIn" />
Expand Down
1 change: 1 addition & 0 deletions docs/en/FrameworksIndex/xamarin-essentials-ios.xml
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,7 @@
<Member Id="M:Xamarin.Essentials.WebAuthenticatorResult.Put(System.String,System.String)" />
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.AccessToken" />
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.ExpiresIn" />
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.IdToken" />
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.Properties" />
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.RefreshToken" />
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.RefreshTokenExpiresIn" />
Expand Down
1 change: 1 addition & 0 deletions docs/en/FrameworksIndex/xamarin-essentials-tvos.xml
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,7 @@
<Member Id="M:Xamarin.Essentials.WebAuthenticatorResult.Put(System.String,System.String)" />
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.AccessToken" />
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.ExpiresIn" />
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.IdToken" />
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.Properties" />
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.RefreshToken" />
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.RefreshTokenExpiresIn" />
Expand Down
1 change: 1 addition & 0 deletions docs/en/FrameworksIndex/xamarin-essentials-uwp.xml
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,7 @@
<Member Id="M:Xamarin.Essentials.WebAuthenticatorResult.Put(System.String,System.String)" />
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.AccessToken" />
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.ExpiresIn" />
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.IdToken" />
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.Properties" />
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.RefreshToken" />
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.RefreshTokenExpiresIn" />
Expand Down
1 change: 1 addition & 0 deletions docs/en/FrameworksIndex/xamarin-essentials-watchos.xml
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,7 @@
<Member Id="M:Xamarin.Essentials.WebAuthenticatorResult.Put(System.String,System.String)" />
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.AccessToken" />
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.ExpiresIn" />
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.IdToken" />
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.Properties" />
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.RefreshToken" />
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.RefreshTokenExpiresIn" />
Expand Down
1 change: 1 addition & 0 deletions docs/en/FrameworksIndex/xamarin-essentials.xml
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,7 @@
<Member Id="M:Xamarin.Essentials.WebAuthenticatorResult.Put(System.String,System.String)" />
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.AccessToken" />
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.ExpiresIn" />
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.IdToken" />
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.Properties" />
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.RefreshToken" />
<Member Id="P:Xamarin.Essentials.WebAuthenticatorResult.RefreshTokenExpiresIn" />
Expand Down
36 changes: 27 additions & 9 deletions docs/en/Xamarin.Essentials/WebAuthenticatorResult.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<Parameters />
<Docs>
<summary>
<para />
<para></para>
</summary>
<remarks>To be added.</remarks>
</Docs>
Expand Down Expand Up @@ -127,13 +127,31 @@
<param name="key">Key from the callback URI's query string.</param>
<summary>Gets a value for a given key from the dictionary.</summary>
<returns>
<para />
<para></para>
</returns>
<remarks>
<para />
<para></para>
</remarks>
</Docs>
</Member>
<Member MemberName="IdToken">
<MemberSignature Language="C#" Value="public string IdToken { get; }" />
<MemberSignature Language="ILAsm" Value=".property instance string IdToken" />
<MemberSignature Language="DocId" Value="P:Xamarin.Essentials.WebAuthenticatorResult.IdToken" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>Xamarin.Essentials</AssemblyName>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.String</ReturnType>
</ReturnValue>
<Docs>
<summary>The value for the `id_token` key.</summary>
<value>The value for the `id_token` key.</value>
<remarks>Apple doesn't return an access token on iOS native sign in, but it does return id_token as a JWT.</remarks>
</Docs>
</Member>
<Member MemberName="Properties">
<MemberSignature Language="C#" Value="public System.Collections.Generic.Dictionary&lt;string,string&gt; Properties { get; set; }" />
<MemberSignature Language="ILAsm" Value=".property instance class System.Collections.Generic.Dictionary`2&lt;string, string&gt; Properties" />
Expand All @@ -149,10 +167,10 @@
<Docs>
<summary>The dictionary of key/value pairs parsed form the callback URI's querystring.</summary>
<value>
<para />
<para></para>
</value>
<remarks>
<para />
<para></para>
</remarks>
</Docs>
</Member>
Expand All @@ -174,14 +192,14 @@
</Parameters>
<Docs>
<param name="key">
<para />
<para></para>
</param>
<param name="value">
<para />
<para></para>
</param>
<summary>Puts a key/value pair into the dictionary.</summary>
<remarks>
<para />
<para></para>
</remarks>
</Docs>
</Member>
Expand All @@ -201,7 +219,7 @@
<summary>The value for the `refresh_token` key.</summary>
<value>Refresh Token parsed from the callback URI refresh_token parameter.</value>
<remarks>
<para />
<para></para>
</remarks>
</Docs>
</Member>
Expand Down

0 comments on commit 38814da

Please sign in to comment.