Skip to content

Commit

Permalink
OKTA-526775 fix ODE in iOS (#100)
Browse files Browse the repository at this point in the history
Fixes #97
  • Loading branch information
bryanapellanes-okta authored Sep 30, 2022
1 parent d8a43e8 commit d2088f4
Show file tree
Hide file tree
Showing 23 changed files with 111 additions and 18 deletions.
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
# Changelog
Running changelog of releases since `1.0.0-beta01`

## v3.1.1

### Changes

- Update Xamarin.Forms dependency to version 5.0.0.2515
- Add `OktaPlatform.InitAsync(...)` overloads that accept `UIWindow` instead of `UIViewController` to prevent potential `ObjectDisposedException` that may occur on `SignOut` if `Window.RootViewController` is disposed after initialization
- Deprecate `OktaPlatform.InitAsync(...)` overloads that accept `UIViewController`

## v3.1.0

Encapsulated initialization process.

### Changes

- Update Xamarin.Forms dependency to version 5.0.0.2478
- Update Xamarin.Essentials dependency to version 1.7.3
- Deprecate Okta specific AppDelegate in iOS
- Deprecate Okta specific Activity in Android

### Features

- OktaPlatform class - encapsulates initialization process
- OktaPlatform.InitAsync(...)
- iOS - OktaPlatform.IsOktaCallback(...)
- Android - OktaPlatform.HandleCallback(...)

## v3.0.2

### Fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
<PackageReference Include="Xamarin.Android.Support.CustomTabs">
<Version>28.0.0.3</Version>
</PackageReference>
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2478" />
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2515" />
<PackageReference Include="Xamarin.Essentials" Version="1.7.3" />
</ItemGroup>
<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions Okta.Xamarin/Okta.Xamarin.Android/Okta.Xamarin.Android.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>Okta.Xamarin.Android</id>
<version>3.1.0</version>
<version>3.1.1</version>
<authors>Okta, Inc.</authors>
<owners>Okta, Inc.</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
Expand All @@ -15,7 +15,7 @@
<tags>okta token authentication authorization oauth sso oidc</tags>
<repository type="Git" url="https://github.com/okta/okta-oidc-xamarin.git" />
<dependencies>
<dependency id="Okta.Xamarin" version="3.1.0" />
<dependency id="Okta.Xamarin" version="3.1.1" />
<dependency id="System.Net.Http" version="4.3.4" />
<dependency id="Xamarin.Essentials" version="1.7.3" />
<dependency id="Xamarin.Forms" version="5.0.0.2478" />
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Okta.Xamarin/Okta.Xamarin.iOS/Okta.Xamarin.iOS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
<PackageReference Include="System.Net.Http">
<Version>4.3.4</Version>
</PackageReference>
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2478" />
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2515" />
<PackageReference Include="Xamarin.Essentials" Version="1.7.3" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
Expand Down
4 changes: 2 additions & 2 deletions Okta.Xamarin/Okta.Xamarin.iOS/Okta.Xamarin.iOS.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>Okta.Xamarin.iOS</id>
<version>3.1.0</version>
<version>3.1.1</version>
<authors>Okta, Inc.</authors>
<owners>Okta, Inc.</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
Expand All @@ -15,7 +15,7 @@
<tags>okta token authentication authorization oauth sso oidc</tags>
<repository type="Git" url="https://github.com/okta/okta-oidc-xamarin.git" />
<dependencies>
<dependency id="Okta.Xamarin" version="3.1.0" />
<dependency id="Okta.Xamarin" version="3.1.1" />
<dependency id="System.Net.Http" version="4.3.4" />
<dependency id="Xamarin.Essentials" version="1.7.3" />
<dependency id="Xamarin.Forms" version="5.0.0.2478" />
Expand Down
32 changes: 32 additions & 0 deletions Okta.Xamarin/Okta.Xamarin.iOS/OktaPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,56 @@
// </copyright>

using Foundation;
using System;
using System.Threading.Tasks;
using UIKit;

namespace Okta.Xamarin.iOS
{
public class OktaPlatform : OktaPlatformBase
{
/// <summary>
/// Detrmines if the specified url matches the configured `RedirectUri` or the configured `PostLogoutRedirectUri`. Designed to be called from AppDelegate.OpenUrl.
/// </summary>
/// <param name="application">The main application.</param>
/// <param name="url">The url.</param>
/// <param name="sourceApplication">The source application.</param>
/// <param name="annotation">The annotation</param>
/// <returns>True if a match is found.</returns>
public static bool IsOktaCallback(UIApplication application, NSUrl url, string sourceApplication, NSObject annotation
)
{
return iOsOidcClient.IsOktaCallback(application, url, sourceApplication, annotation);
}

/// <summary>
/// Initialize the Okta platform.
/// </summary>
/// <param name="iOSWindow">The main application window.</param>
/// <returns>OktaContext.</returns>
public static async Task<OktaContext> InitAsync(UIWindow iOSWindow)
{
return await InitAsync(iOSWindow, iOsOktaConfig.LoadFromPList("OktaConfig.plist"));
}

/// <summary>
/// Initalize the Okta platform.
/// </summary>
/// <param name="iOSWindow">The main application window.</param>
/// <param name="config">The configuration.</param>
/// <returns>OktaContext.</returns>
public static async Task<OktaContext> InitAsync(UIWindow iOSWindow, IOktaConfig config)
{
return await InitAsync(new iOsOidcClient(iOSWindow, config));
}

[Obsolete("Use InitAsync(UIWindow iOSWindow) instead.")]
public static async Task<OktaContext> InitAsync(UIViewController iOSViewController)
{
return await InitAsync(iOSViewController, iOsOktaConfig.LoadFromPList("OktaConfig.plist"));
}

[Obsolete("Use InitAsync(UIWindow iOSWindow, IOktaConfig config) instead.")]
public static async Task<OktaContext> InitAsync(UIViewController iOSViewController, IOktaConfig config)
{
return await InitAsync(new iOsOidcClient(iOSViewController, config));
Expand Down
36 changes: 35 additions & 1 deletion Okta.Xamarin/Okta.Xamarin.iOS/iOSOidcClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,31 @@ public class iOsOidcClient: OidcClient
private static Lazy<string> userAgent = new Lazy<string>(() => $"Okta-Xamarin-Sdk/iOS-{Assembly.GetExecutingAssembly().GetName().Version}");

#pragma warning disable IDE1006 // Naming Styles
UIViewController _iOsViewController;
/// <summary>
/// Stores a reference to the current iOS <see cref="UIKit.UIViewController"/>, for use in launching the browser for login
/// </summary>
private UIKit.UIViewController iOSViewController { get; set; }
private UIKit.UIViewController iOSViewController
{
get
{
if (iOSWindow != null)
{
return iOSWindow.RootViewController;
}
return _iOsViewController;
}
set
{
if (iOSWindow != null)
{
iOSWindow.RootViewController = value;
}
_iOsViewController = value;
}
}

private UIKit.UIWindow iOSWindow { get; set; }
#pragma warning restore IDE1006 // Naming Styles

/// <summary>
Expand All @@ -38,11 +59,24 @@ protected override void LaunchBrowser(string url)
iOSViewController.PresentViewControllerAsync(SafariViewController, true);
}

/// <summary>
/// Creates a new iOS Okta OidcClient, attached to the provided <see cref="UIKit.UIWindow"/> and based on the specified <see cref="OktaConfig"/>.
/// </summary>
/// <param name="window">A reference to the current iOS <see cref="UIKit.UIWindow"/>, for use in launching the browser for login and logout.</param>
/// <param name="config">The <see cref="OktaConfig"/> to use for this client. The config must be valid at the time this is called.</param>
public iOsOidcClient(UIWindow window, IOktaConfig config)
{
this.iOSWindow = window;
this.Config = config;
validator.Validate(Config);
}

/// <summary>
/// Creates a new iOS Okta OidcClient, attached to the provided <see cref="UIKit.UIViewController"/> and based on the specified <see cref="OktaConfig"/>
/// </summary>
/// <param name="iOSViewController">A reference to the current iOS <see cref="UIKit.UIViewController"/>, for use in launching the browser for login</param>
/// <param name="config">The <see cref="OktaConfig"/> to use for this client. The config must be valid at the time this is called.</param>
[Obsolete("Use iOsOidcClient(UIWindow window, IOktaConfig config) instead.")]
public iOsOidcClient(UIKit.UIViewController iOSViewController, IOktaConfig config)
{
while (iOSViewController?.PresentedViewController != null)
Expand Down
1 change: 1 addition & 0 deletions Okta.Xamarin/Okta.Xamarin.sln
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ Global
{F7AADB5C-B6FE-48D7-AC10-8F033A19B8CB}.Debug|Any CPU.ActiveCfg = Debug|iPhoneSimulator
{F7AADB5C-B6FE-48D7-AC10-8F033A19B8CB}.Debug|iPhone.ActiveCfg = Debug|iPhone
{F7AADB5C-B6FE-48D7-AC10-8F033A19B8CB}.Debug|iPhone.Build.0 = Debug|iPhone
{F7AADB5C-B6FE-48D7-AC10-8F033A19B8CB}.Debug|iPhone.Deploy.0 = Debug|iPhone
{F7AADB5C-B6FE-48D7-AC10-8F033A19B8CB}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator
{F7AADB5C-B6FE-48D7-AC10-8F033A19B8CB}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator
{F7AADB5C-B6FE-48D7-AC10-8F033A19B8CB}.Release|Android.ActiveCfg = Release|iPhoneSimulator
Expand Down
6 changes: 3 additions & 3 deletions Okta.Xamarin/Okta.Xamarin/Okta.Xamarin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Company>Okta</Company>
<Authors>Okta, Inc.</Authors>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<Version>3.0.2</Version>
<Version>3.1.1</Version>
<PackageTags>okta,token,authentication,authorization</PackageTags>
<RepositoryUrl>https://github.com/okta/okta-oidc-xamarin/</RepositoryUrl>
<PackageProjectUrl>https://github.com/okta/okta-oidc-xamarin/</PackageProjectUrl>
Expand All @@ -18,13 +18,13 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Xamarin.Essentials" Version="1.7.3" />
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2478" />
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2515" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Okta.Xamarin/Okta.Xamarin/Okta.Xamarin.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>Okta.Xamarin</id>
<version>3.1.0</version>
<version>3.1.1</version>
<authors>Okta, Inc.</authors>
<owners>Okta, Inc.</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
Expand Down
2 changes: 1 addition & 1 deletion nuget/Android/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.0
3.1.1
2 changes: 1 addition & 1 deletion nuget/Common/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.0
3.1.1
2 changes: 1 addition & 1 deletion nuget/iOS/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.0
3.1.1
Binary file removed nuget/packages/Okta.Xamarin.3.1.0.nupkg
Binary file not shown.
Binary file added nuget/packages/Okta.Xamarin.3.1.1.nupkg
Binary file not shown.
Binary file removed nuget/packages/Okta.Xamarin.Android.3.1.0.nupkg
Binary file not shown.
Binary file added nuget/packages/Okta.Xamarin.Android.3.1.1.nupkg
Binary file not shown.
Binary file removed nuget/packages/Okta.Xamarin.iOS.3.1.0.nupkg
Binary file not shown.
Binary file added nuget/packages/Okta.Xamarin.iOS.3.1.1.nupkg
Binary file not shown.
2 changes: 1 addition & 1 deletion nuget/semver/minor
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0
1
2 changes: 1 addition & 1 deletion nuget/semver/patch
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0
1
2 changes: 1 addition & 1 deletion nuget/semver/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.0
3.1.1

0 comments on commit d2088f4

Please sign in to comment.