question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Enhancement] Allow injecting the Parent Activity/Window in the Client Builder

See original GitHub issue

Description

The UI Parent (Window on UWP/Activity on Android) should be injected at the Client Application Builder level and not be required at the AcquireTokenInteractiveParameterBuilder level.

Current 3.0 API

var pca = PublicClientApplicationBuilder.Create(options.ClientId)
                                        .WithB2CAuthority(authority)
                                        .Build();

var result = await pca.AcquireTokenInteractive(Scopes)
                      .WithParentActivityOrWindow(Parent)
                      .ExecuteAsync();

Expected 3.0 API

var pca = PublicClientApplicationBuilder.Create(options.ClientId)
                                        .WithB2CAuthority(authority)
                                        .WithParentActivityOrWindow(Parent)
                                        .Build();

var result = await pca.AcquireTokenInteractive(Scopes)
                      .ExecuteAsync();

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:27 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
HappyNomadcommented, Apr 23, 2019

I’m in favor of the WithParentActivityOrWindow method going away. My auth code is in the view-model. Regardless of possible trickery for obtaining the window reference there, I’m opposed to view objects even passing through that layer.

1reaction
dansiegelcommented, Apr 23, 2019

I would say this perhaps relates to #1104 since both these issues are around the ParentActivityOrWindow. The more I think about it, the more I’m thinking that perhaps we’re looking at the entirely wrong places. Perhaps this could all be simplified with a platform specific activity ONLY on those platforms where there is such a need.

public static class MSALActivityLocator
{
    public static Activity CurrentActivity { get; set; }
}

[Application]
class App : Application, Application.IActivityLifecycleCallbacks
{
    public void OnActivityCreated(Activity activity, Bundle savedInstanceState)
    {
        MSALActivityLocator.CurrentActivity = activity;
    }
}

Alternatively you could do what I do personally and take a dependency on Plugin.CurrentActivity. The benefit here, is that you’re not introducing a new API, and using a dependency most Xamarin.Android developers are already used to using.

[Application]
class App : Application, Application.IActivityLifecycleCallbacks
{
    public void OnActivityCreated(Activity activity, Bundle savedInstanceState)
    {
        CrossCurrentActivity.Current.Activity = activity;
    }
}

// Alternatively:
public class MainActivity : FormsAppCompatActivity
{
    protected override void OnCreate(Bundle bundle)
    {
        CrossCurrentActivity.Current.Activity = this;
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Injecting parent component with base class type in angular
I'm trying to inject my parent component into a child component (tight cupling, I know). The problem is I have an inheritance chain...
Read more >
Dependency injection with Hilt
Doing manual dependency injection requires you to construct every class and its dependencies by hand, and to use containers to reuse and manage...
Read more >
Provide / Inject
Any component in the descendant tree, regardless of how deep it is, can inject dependencies provided by components up in its parent chain....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found