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

Commit

Permalink
Updated for v4.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianhall committed Nov 6, 2020
1 parent c2def10 commit 928d643
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 106 deletions.
30 changes: 21 additions & 9 deletions docs/chapter2/enterprise.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,7 @@ Repeat for each test user you wish to use. Once done, move onto configuring you
Make sure you create the app service in the right directory / subscription. If you have access to more than one directory, you can choose the right one by selecting it under your account drop-down in the top-right corner.

There is also an **Advanced** track. This is used in client-flow situations and in situations where you have more
than one directory. The Express flow is great for getting started quickly.

!!! info "Preview Portal Access"
Azure Active Directory portal access is in preview right now. Certain things can only be done through
the [Azure Classic Portal][classic-portal]. The list of things that cannot be done in the Azure Portal
is thankfully dwindling.
than one directory. It's also used if you want to use the newer MSAL library for authentication. The Express flow is great for getting started quickly.

You can walk through a server-flow authentication to test that you have all the settings correct. Point your browser at https://_yoursite_.azurewebsites.net/.auth/login/aad. The browser will take you through an authentication flow before giving you a successful authentication image:

Expand Down Expand Up @@ -193,7 +188,7 @@ Let us take a closer look at this implementation. The `LoginAsync()` method on

Note that we need an extra initialization routine for Android that must be called prior the login provider being
called to pass along the main window of the app (also known as the context). This is done in the `MainActivity.cs`
file **after** the Xamarin Forms initialization call. The dependency service is not set up until after the Xamarin
file **after** the Xamarin Forms initialization call. In addition, Azure Mobile Apps uses Xamarin.Essentials under the covers, and that requires that you handle the callback. The dependency service is not set up until after the Xamarin
Forms library is initialized, so we will not be able to get the login provider reference before that point:

```csharp
Expand All @@ -209,10 +204,27 @@ protected override void OnCreate(Bundle bundle)

LoadApplication(new App());
}

protected override void OnResume()
{
base.OnResume();
Xamarin.Essentials.Platform.OnResume();
}
```

iOS is similar, but does not require the initialization step in the main startup class. However, it does require handling the callback in the AppDelegate.cs:

```csharp
public override bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options)
{
if (Xamarin.Essentials.Platform.OpenUrl(app, url, options)) {
return true;
}
return base.OpenUrl(app, url, options);
}
```

iOS is similar, but does not require the initialization step in the main startup class. The login provider class
is in `Services\iOSLoginProvider.cs` (in the **TaskList.iOS** project):
The login provider class is in `Services\iOSLoginProvider.cs` (in the **TaskList.iOS** project):

```csharp
using System.Threading.Tasks;
Expand Down
95 changes: 3 additions & 92 deletions docs/chapter2/social.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
## Social Authentication

Azure App Service provides built-in support for Facebook, Google, Microsoft and Twitter. Irrespective of whether
you intend to use server-flow or client-flow, you will need to configure the Azure App Service Authentication /
Authorization service. The method is pretty similar in each case:
Azure App Service provides built-in support for Facebook and Google. Microsoft and Twitter are also accepted, but Microsoft authentication is handled within the context of Azure Active Directory (and is an option when creating the app registration), and Twitter uses the older (and insecure) OAuth v1 protocol. It should not be used.

Irrespective of whether you intend to use server-flow or client-flow, you will need to configure the Azure App Service Authentication / Authorization service. The method is pretty similar in each case:

1. Obtain a Developer Account for the provider.
2. Create a new application, obtaining a Client ID and Secret.
Expand Down Expand Up @@ -146,95 +146,6 @@ If you happen to mis-type the Authorized redirect URI, Google will inform you th
!!! warn
Google has changed the security semantics for its authentication service. You must use the v3.1.0 of the Azure Mobile Apps Client SDK for Server Flow authentication with Google to work.

## Microsoft Account Configuration

The advantage of the Microsoft Account (or MSA, as it is known) is that you already have an account - you need
one for accessing Azure in general. Go to the [Microsoft Account Developer Center][13] and log on with
your Microsoft account. You should use the same one as you use for Azure, but it is not required.

![Microsoft Account Developer Center][img14]

Just to confuse us, there are two **Add an App** buttons. Strangely, they are different. Click the one next to
**Converged applications**.

![MSA: Create an application][img15]

Enter an awesome name, then lick **Create application**.

![MSA: Add a Platform][img16]

Click **Add Platform**, followed by **Web**. In the **Redirect URIs**, enter your app URL +
`/.auth/login/microsoftaccount/callback`. Then Click **Save**.

![MSA: Redirect URI][img17]

Now Click **Generate New Password** under **Application Secrets**.

![MSA: New password][img18]

Unlike the other social providers, this is the only time you will get to see your client secret, so make a note of it or copy and paste it into a notepad. Once you have it copied somewhere, Click **OK**, followed by **Save**.

You now have all the information you need to configure the Microsoft Account section within your App Server
Authentication / Authorization. The Client ID you need to enter is the Application ID and the Client Secret is the
password you just copied somewhere.

![MSA: Configuration of App Service][img19]

Note that you have to choose claims that you want to read. The **wl.basic** and **wl.emails** will give you enough
information to get started with this tutorial.

Click **OK** (at the bottom), followed by **Save** (at the top). You can test the settings by pointing your browser
to https://_yoursite_.azurewebsites.net/.auth/login/microsoftaccount. You will see what should be a normal claims
request page:

![MSA: Claims Request][img20]

Clicking on **Yes** should take you to the normal success page.

## Twitter Configuration

I hope you are seeing that all the OAuth providers take a very similar route to configuring their service. The semantics of the service are slightly different in each case. Twitter is no different. As you might expect, before continuing, sign up for [Twitter][14]. Once you have signed up, the [Twitter Developers Portal][15] is your next stop. Once there, click **Create New App**:

![Twitter: New App][img21]

Most of the fields are self-explanatory. The **Callback URL** is the same thing that the other social providers have
called the Redirect URL. The appropriate value is your app URL + `/.auth/login/twitter/callback`. There is a legal
agreement at the bottom of the page, then you can Click **Create your Twitter application** button.

!!! danger
All social authentication providers have some sort of legal agreement that governs their use. In general, demo or
PoC apps are fair use. However, you should get a legal opinion before using a social authentication provider in a
production app.

Once you have created the app, you will get a tabbed display with all the settings. Click the **Keys and Access
Tokens** tab:

![Twitter: Keys][img22]

Note the values for the **Consumer Key (API Key)** and **Consumer Secret (API Secret)**. They get entered into the
Azure Portal.

!!! warn
There is a check box in the **Settings** tab that says _Allow this application to be used to Sign in with Twitter_.
At the time of writing, this is checked by default. However, if you find you can not log in for some reason, then
ensure this checkbox is checked.

Back in the Azure Portal, select your app service, then **All Settings**, **Authentication / Authorization**, and
finally **Twitter** (assuming you have already turned Authentication on). You can now cut and paste the Consumer
Key and Consumer Secret into the appropriate boxes, before clicking on **OK** (at the bottom) followed by **Save**
(at the top).

As with the other providers, you should test the authentication flow by pointing your browser to
https://_yoursite_.azurewebsites.net/.auth/login/twitter.

![Twitter: Authorize App][img23]

Clicking on **Authorize app** should show you our normal successful authentication screen.

The social authentication providers should now all be configured to handle a web-based or server-flow authentication
request. There are times when configuring a client-flow authentication is different. We will point those out when we
get to them.

## Adding Authentication to a Mobile Client

Now that the backend is completely configured, we can move our attention to the mobile client. We are going to be
Expand Down
7 changes: 7 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ notifications.
This book does not tell you everything there is to know about either topic. It
focuses on the topics necessary to get your mobile apps connected to the cloud.

> **UPDATE: .NET Client v4.2.0**
>
> In November 2020, Microsoft released v4.2.0 of the .NET Client, which upgraded
> support to .NET Standard 2.0, along with support for the latest versions of the
> iOS and Android operating systems. As a result, some instructions are out of
> date. I'm in progress of updating the documentation to reflect this change.
## What are Cloud Connected Mobile Apps?

I guess I should define some of the terminology that I am going to use. When I
Expand Down
10 changes: 5 additions & 5 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ site_url: https://adrianhall.github.io/develop-mobile-apps-with-csharp-and-azure
repo_url: https://github.com/adrianhall/develop-mobile-apps-with-csharp-and-azure
repo_name: GitHub
site_author: Adrian Hall
copyright: 'Copyright © 2017 Adrian Hall'
copyright: 'Copyright © 2017-2020 Adrian Hall'
nav:
- Getting Started: index.md
- Chapter 1 - Introduction:
Expand Down Expand Up @@ -65,10 +65,10 @@ extra:
primary: 'red'
accent: 'deep purple'
social:
- type: 'github'
link: 'https://github.com/adrianhall'
- type: 'twitter'
link: 'https://twitter.com/FizzyInTheHall'
- icon: fontawesome/brands/github-alt
link: https://github.com/adrianhall
- icon: fontawesome/brands/twitter
link: https://twitter.com/FizzyInTheHall
markdown_extensions:
- toc:
permalink: true
Expand Down

0 comments on commit 928d643

Please sign in to comment.