Skip to content

Commit

Permalink
Release v2.0.0 (#48)
Browse files Browse the repository at this point in the history
* delete demo app from Okta.Xamarin; start Okta.Xamarin.Demo app (#46)

* Revoke & Renew implementation (#47)
  • Loading branch information
bryanapellanes-okta authored Jul 13, 2021
1 parent 8eb0d79 commit c53772e
Show file tree
Hide file tree
Showing 100 changed files with 9,629 additions and 5,066 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Changelog
Running changelog of releases since `1.0.0-beta01`

## v2.0.0

Cleanup and continued refinement of existing features.

- Removed demo application from primary binaries
- Fixed Revoke & Renew implementations

## v1.0.0

This is the first stable release of the Okta Xamarin Sdk.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
<AndroidUseLatestPlatformSdk>false</AndroidUseLatestPlatformSdk>
<TargetFrameworkVersion>v10.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v11.0</TargetFrameworkVersion>
<AndroidEnableSGenConcurrent>true</AndroidEnableSGenConcurrent>
<AndroidUseAapt2>true</AndroidUseAapt2>
<AndroidHttpClientHandlerType>Xamarin.Android.Net.AndroidClientHandler</AndroidHttpClientHandlerType>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.okta.xamarin.android" android:installLocation="auto">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="29" />
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="30" />
<application android:label="Okta.Xamarin.Android" android:theme="@style/MainTheme"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
10 changes: 8 additions & 2 deletions Okta.Xamarin/Okta.Xamarin/IOidcClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Licensed under the Apache 2.0 license. See the LICENSE file in the project root for full license information.
// </copyright>

using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Security.Claims;
Expand All @@ -16,14 +17,19 @@ namespace Okta.Xamarin
public interface IOidcClient
{
/// <summary>
/// Gets or sets the last API response, primarily for debugging.
/// The event that is raised when an API exception occurs.
/// </summary>
event EventHandler<RequestExceptionEventArgs> RequestException;

/// <summary>
/// Gets the last API response, primarily for debugging.
/// </summary>
HttpResponseMessage LastApiResponse { get; }

/// <summary>
/// Gets the OAuthException that occurred if any. Will be null if no exception occurred.
/// </summary>
OAuthException OAuthException{ get; }
OAuthException OAuthException { get; }

/// <summary>
/// The configuration for this client instance.
Expand Down
16 changes: 15 additions & 1 deletion Okta.Xamarin/Okta.Xamarin/IOktaStateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ namespace Okta.Xamarin
/// </summary>
public interface IOktaStateManager
{
/// <summary>
/// The event that is raised when an API exception occurs.
/// </summary>
event EventHandler<RequestExceptionEventArgs> RequestException;

/// <summary>
/// Gets the access token.
/// </summary>
Expand Down Expand Up @@ -113,9 +118,18 @@ public interface IOktaStateManager
/// </summary>
/// <param name="refreshIdToken">A value indicating whether to also renew the ID token.</param>
/// <param name="authorizationServerId">The authorization server ID.</param>
/// <returns>Task{RenewResponse}</returns>
/// <returns>Task{RenewResponse}.</returns>
Task<RenewResponse> RenewAsync(bool refreshIdToken = false, string authorizationServerId = "default");

/// <summary>
/// Renews tokens.
/// </summary>
/// <param name="refreshToken">The refresh token.</param>
/// <param name="refreshIdToken">A value indicating whether to refresh the ID token.</param>
/// <param name="authorizationServerId">The authorization server.</param>
/// <returns>Task{RenewResponse}.</returns>
Task<RenewResponse> RenewAsync(string refreshToken, bool refreshIdToken = false, string authorizationServerId = "default");

/// <summary>
/// Revokes tokens associated with this OktaState.
/// </summary>
Expand Down
61 changes: 42 additions & 19 deletions Okta.Xamarin/Okta.Xamarin/OidcClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
// Licensed under the Apache 2.0 license. See the LICENSE file in the project root for full license information.
// </copyright>

using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net.Http;
using System.Security.Claims;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace Okta.Xamarin
{
Expand All @@ -21,12 +20,17 @@ namespace Okta.Xamarin
/// </summary>
public abstract class OidcClient : IOidcClient
{
OAuthException oauthException;
private OAuthException oauthException;

/// <summary>
/// Gets the OAuthException that occurred if any. Will be null if no exception occurred.
/// The event that is raised when an API exception occurs.
/// </summary>
public OAuthException OAuthException
public event EventHandler<RequestExceptionEventArgs> RequestException;

/// <summary>
/// Gets or sets the OAuthException that occurred if any. Is null if no exception occurred.
/// </summary>
public OAuthException OAuthException
{
get
{
Expand Down Expand Up @@ -213,6 +217,7 @@ public async Task<T> RenewAsync<T>(string refreshToken, bool refreshIdToken = fa

protected async Task<string> GetRenewJsonAsync(string refreshToken, bool refreshIdToken = false, string authorizationServerId = "default")
{
// for details see: https://developer.okta.com/docs/guides/refresh-tokens/use-refresh-token/
string scope = "offline_access";
if (refreshIdToken)
{
Expand All @@ -234,7 +239,6 @@ protected async Task<string> GetIntrospectJsonAsync(string token, string tokenTy
{
{ "token", token },
{ "token_type_hint", tokenTypeHint },
{ "client_id", Config.ClientId },
}, authorizationServerId);
}

Expand Down Expand Up @@ -290,23 +294,42 @@ protected virtual async Task<string> PerformAuthorizationServerRequestAsync(Http

protected virtual async Task<string> PerformAuthorizationServerRequestAsync(HttpMethod httpMethod, string path, Dictionary<string, string> headers, string authorizationServerId = "default", params KeyValuePair<string, string>[] formUrlEncodedContent)
{
FormUrlEncodedContent content = null;
if ((bool)formUrlEncodedContent?.Any())
try
{
content = new FormUrlEncodedContent(formUrlEncodedContent.ToList());
}
FormUrlEncodedContent content = null;
if ((bool)formUrlEncodedContent?.Any())
{
content = new FormUrlEncodedContent(formUrlEncodedContent.ToList());
}

if (!path.StartsWith("/"))
if (!path.StartsWith("/"))
{
path = $"/{path}";
}

var request = GetHttpRequestMessage(httpMethod, $"{GetAuthorizationServerBasePath(authorizationServerId)}{path}", headers);
request.Content = content;

HttpResponseMessage response = await client.SendAsync(request).ConfigureAwait(false);
this.LastApiResponse = response;
response.EnsureSuccessStatusCode();

return await response.Content.ReadAsStringAsync().ConfigureAwait(false);
}
catch (Exception ex)
{
path = $"/{path}";
this.OnRequestException(new RequestExceptionEventArgs(ex, httpMethod, path, headers, authorizationServerId, formUrlEncodedContent));
return string.Empty;
}
}

var request = GetHttpRequestMessage(httpMethod, $"{GetAuthorizationServerBasePath(authorizationServerId)}{path}", headers);
request.Content = content;

HttpResponseMessage response = await client.SendAsync(request).ConfigureAwait(false);
LastApiResponse = response;
return await response.Content.ReadAsStringAsync().ConfigureAwait(false);
/// <summary>
/// Raises the RequestException event.
/// </summary>
/// <param name="args">Data relevant to the event.</param>
protected virtual void OnRequestException(RequestExceptionEventArgs args)
{
this.RequestException?.Invoke(this, args);
}

protected virtual string GetBasePath()
Expand Down Expand Up @@ -452,7 +475,7 @@ private async Task ExchangeAuthCodeForToken(string code)
data["token_type"],
data.GetValueOrDefault("id_token"),
data.GetValueOrDefault("refresh_token"),
data.ContainsKey("expires_in") ? (int?)(int.Parse(data["expires_in"])) : null,
data.ContainsKey("expires_in") ? (int?)int.Parse(data["expires_in"]) : null,
data.GetValueOrDefault("scope") ?? this.Config.Scope)
{
Config = Config,
Expand Down
12 changes: 0 additions & 12 deletions Okta.Xamarin/Okta.Xamarin/Okta.Xamarin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,5 @@
<Compile Update="OktaApp.xaml.cs">
<DependentUpon>OktaApp.xaml</DependentUpon>
</Compile>
<Compile Update="OktaAppShell.xaml.cs">
<DependentUpon>OktaAppShell.xaml</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Views\DiagnosticsPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Views\ProfilePage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>
</Project>
32 changes: 0 additions & 32 deletions Okta.Xamarin/Okta.Xamarin/OktaApp.xaml.cs

This file was deleted.

24 changes: 0 additions & 24 deletions Okta.Xamarin/Okta.Xamarin/OktaAppShell.xaml.cs

This file was deleted.

Loading

0 comments on commit c53772e

Please sign in to comment.