These examples show how to build a Xamarin.Forms project (targeting iOS and Android) that uses Okta for easy login. Under the hood, OpenID Connect and the AppAuth pattern is used.
Please read the blog post to see how this app was created.
Prerequisites: Visual Studio or Visual Studio for Mac with Xamarin installed.
Okta has Authentication and User Management APIs that reduce development time with instant-on, scalable user infrastructure. Okta's intuitive API and expert support make it easy for developers to authenticate, manage, and secure users and roles in any application.
To install this example application, run the following commands:
git clone https://github.com/oktadeveloper/okta-appauth-xamarin-example
cd okta-appauth-xamarin-example
Open OktaDemo.SF.sln
in Visual Studio and compile the project.
You will need to create an application in Okta to perform authentication.
Log in to your Okta Developer account (or sign up if you don’t have an account) and navigate to Applications > Add Application. Click Native, click Next, and give the application a name you’ll remember. The default settings are fine! Click Done to create the application.
Scroll to the bottom of the General tab to find the client ID. You'll need this value in the next step.
Open the OktaDemo.XF/Helpers/Constants.cs
file and update these values:
{clientId}
- The client ID of the Okta application{redirectUri}
- The native redirect URI, likecom.oktapreview.nate-example:/callback
{yourOktaDomain}
- Replace with your Okta domain, found at the top-right of the Dashboard page
Note: The value of {yourOktaDomain}
should be something like dev-123456.oktapreview.com
. Make sure you don't include -admin
in the value!
Open the OktaDemo.XF.Android/Properties/AndroidManifest.xml
file and update the android:scheme
property:
<data android:scheme="com.oktapreview.nate-example"/>
⚠️ Note: There is currently a known issue with native redirects on Android. For more information, see this issue.
Open the OktaDemo.XF/OktaDemo.XF.iOS/Info.plist
file and update the CFBundleURLSchemes
property:
<key>CFBundleURLSchemes</key>
<array>
<string>com.oktapreview.nate-example</string>
</array>
If you aren't familiar with Xamarin and want to learn the basics, start with this blog post: Build an App for iOS and Android with Xamarin
If you're building native (non-Xamarin) apps, you can use Okta's AppAuth SDKs:
Please post any questions as comments on the blog post, or visit our Okta Developer Forums. You can also email [email protected] if would like to create a support ticket.
Apache 2.0, see LICENSE.