Skip to content

Commit

Permalink
Improving the message that there is no longer a UIParent but a Parent…
Browse files Browse the repository at this point in the history
… Object (#65)
  • Loading branch information
jmprieur committed Apr 2, 2019
1 parent 1445109 commit ac26368
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
11 changes: 6 additions & 5 deletions README.md
Expand Up @@ -172,7 +172,7 @@ The structure of the solution is straightforward. All the application logic and
{
try
{
authResult = await App.PCA.AcquireTokenInteractive(App.Scopes, App.UiParent)
authResult = await App.PCA.AcquireTokenInteractive(App.Scopes, App.ParentWindow)
.ExecuteAsync();

/* display info*/
Expand All @@ -184,16 +184,17 @@ The structure of the solution is straightforward. All the application logic and
- When the sign in button is pressed, we execute the same logic - but using a method that shows interactive UX:

```CSharp
AuthenticationResult ar = await App.PCA.AcquireTokenInteractive(App.Scopes, App.UiParent);
AuthenticationResult ar = await App.PCA.AcquireTokenInteractive(App.Scopes, App.ParentWindow);
```

- The `Scopes` parameter indicates the permissions the application needs to gain access to the data requested through subsequent web API call (in this sample, encapsulated in `RefreshUserData`).

The `UiParent` is used in Android to tie the authentication flow to the current activity, and in UWP to center the window. It is ignored on iOS. For more platform specific considerations, please see below.
The `parentWindow` is used in Android to tie the authentication flow to the current activity, and in UWP to center the window. It is ignored on iOS. For more platform specific considerations, please see below.

- The sign out logic is very simple. In this sample we have just one user, however we are demonstrating a more generic sign out logic that you can apply if you have multiple concurrent users and you want to clear up the entire cache.

```CSharp
var accounts = await App.PCA.GetAccountsAsync();
while (accounts.Any())
{
await App.PCA.RemoveAsync(accounts.FirstOrDefault());
Expand All @@ -216,10 +217,10 @@ AuthenticationContinuationHelper.SetAuthenticationContinuationEventArgs(requestC

That line ensures that the control goes back to MSAL once the interactive portion of the authentication flow ended.

In `OnCreate`, we need to add the following assignment (the UiParent is the activity)
In `OnCreate`, we need to add the following assignment (the ParentWindow is the activity)

```CSharp
App.UiParent = this;
App.ParentWindow = this;
```

That code ensures that the authentication flows occur in the context of the current activity.
Expand Down
2 changes: 1 addition & 1 deletion UserDetailsClient/UserDetailsClient.Droid/MainActivity.cs
Expand Up @@ -21,7 +21,7 @@ protected override void OnCreate(Bundle bundle)

global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(new App());
App.UiParent = this;
App.ParentWindow = this;
}

protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
Expand Down
2 changes: 1 addition & 1 deletion UserDetailsClient/UserDetailsClient.iOS/AppDelegate.cs
Expand Up @@ -26,7 +26,7 @@ public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
LoadApplication(new App());
App.UiParent = null; // no UI parent on iOS
App.ParentWindow = null; // no UI parent on iOS
return base.FinishedLaunching(app, options);
}

Expand Down
2 changes: 1 addition & 1 deletion UserDetailsClient/UserDetailsClient/App.cs
Expand Up @@ -21,7 +21,7 @@ public class App : Application
public static string[] Scopes = { "User.Read" };
public static string Username = string.Empty;

public static object UiParent { get; set; }
public static object ParentWindow { get; set; }

public App()
{
Expand Down
2 changes: 1 addition & 1 deletion UserDetailsClient/UserDetailsClient/MainPage.xaml.cs
Expand Up @@ -38,7 +38,7 @@ async void OnSignInSignOut(object sender, EventArgs e)
{
try
{
authResult = await App.PCA.AcquireTokenInteractive(App.Scopes, App.UiParent)
authResult = await App.PCA.AcquireTokenInteractive(App.Scopes, App.ParentWindow)
.ExecuteAsync();

await RefreshUserDataAsync(authResult.AccessToken);
Expand Down

0 comments on commit ac26368

Please sign in to comment.