Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Introduce SignInResult/SignOutResult and SignIn/SignOut #4259

Closed
wants to merge 1 commit into from
Closed

Introduce SignInResult/SignOutResult and SignIn/SignOut #4259

wants to merge 1 commit into from

Conversation

kevinchalet
Copy link
Contributor

Fixes #4258.

(FWIW, that would be great if the authentication helpers had overloads accepting a params string[] argument for authenticationSchemes).

/cc @rynowak @HaoK @pranavkm

@dnfclas
Copy link

dnfclas commented Mar 9, 2016

Hi @PinpointTownes, I'm your friendly neighborhood .NET Foundation Pull Request Bot (You can call me DNFBOT). Thanks for your contribution!
You've already signed the contribution license agreement. Thanks!

The agreement was validated by .NET Foundation and real humans are currently evaluating your PR.

TTYL, DNFBOT;


if (authenticationSchemes.Count == 0)
{
// TODO: move the exception message to the resources file.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: what's the recommended way to add new messages to the resources file? The resx KoreBuild target?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup - build resx

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly, it doesn't work on my machine:

& : The module '.build' could not be loaded. For more information, run
'Import-Module .build'.
At C:\Users\Chalet Kévin\Documents\GitHub\Forks\Mvc\.build\KoreBuild.ps1:64
char:2
+ &"$koreBuildFolder\Sake\0.2.2\tools\Sake.exe" -I $koreBuildFolder\sha ...
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (.build\Sake\0.2.2\tools\Sake.ex
   e:String) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : CouldNotAutoLoadModule

I guess it's related to aspnet/Security#688 (comment), since I'm also using Windows 7.

/cc @Eilon

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might need to delete the .build directory. We made a bunch of changes to how we procure and layout the build scripts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, no luck 😢

I ended up manually adding the property/method in the designer file.

@HaoK
Copy link
Member

HaoK commented Mar 9, 2016

Meh, not sure its worth an extension method to do a foreach SignOut.

/// <param name="principal">The <see cref="ClaimsPrincipal"/> containing the user claims.</param>
/// <returns>The created <see cref="SignInResult"/> for the response.</returns>
[NonAction]
public virtual SignInResult SignIn(IList<string> authenticationSchemes, ClaimsPrincipal principal)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this really makes sense, would you really expect someone to sign the same principal into multiple schemes? I would expect different principals would get signed into each scheme in general

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, some ASOS users are doing that to create a cookie and a token with the same principal.

That said, you're probably right, it's surely not a common case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think things look much cleaner with a single scheme for sign in / sign out. You only need multiple schemes for challenge.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay for SignIn but for SignOut, see #4259 (comment).

@danroth27
Copy link
Member

Thank you for the PR! However, this needs to wait until post 1.0.0. We aren't taking additional features into the current release.

@danroth27 danroth27 added this to the Backlog milestone Mar 9, 2016
@kevinchalet
Copy link
Contributor Author

@danroth27 alright.

That said, it's not really a new feature stricto sensu, as it's mainly a copy/paste of existing code, which is itself a tiny wrapper around the authentication APIs.

@davidfowl
Copy link
Member

@danroth27 @Eilon this is such a small change. Do we like the API? If so can we merge it? It feels like polish since we have ChallengeResult, SignInResult and SIgnOut result can clean up some of the template code as well.

@Tratcher @HaoK does it look good?

/// <param name="properties"><see cref="AuthenticationProperties"/> used to perform the sign-in operation.</param>
public SignInResult(string authenticationScheme, ClaimsPrincipal principal, AuthenticationProperties properties)
{
if (authenticationScheme == null)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: should we keep the null guards even if the properties are publicly settable?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either keep the null guards and make the properties read-only, or remove the null guards.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I wonder if we shouldn't simply move these guards to the ExecuteAsync method, prior to calling the authentication manager.

Anyway, I need to fix all the aspnet-contrib projects before going back to this PR. Everything stopped compiling/working and I can't find a workaround...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO better to validate on the parameters + properties. Generally ExecuteAsync won't be called in unit tests, so it be easy to use the result the wrong way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with dual properties + parameters validation, but we'll still have to move the "as at least one element" check of SignOutResult.AuthenticationSchemes elsewhere, since we could validate that for a constructor parameter, but not for a property.

Another approach might be to remove all the public setters and update SignOutResult.AuthenticationSchemes to expose a read-only list. TBH, I have no personal preference, as long as it's consistent everywhere.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We generally want all the action results to have get/set properties. It's really handy to be able to modify things in filters. Speaking of, we should probably make a defensive copy of whatever list the user passes in.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a tiny check in both SignInResult.ExecuteAsync and SignOutResult.ExecuteAsync to ensure the AuthenticationScheme(s) property is not left is an incoherent state (null or empty, basically).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rynowak do you strongly feel we should do some ToArray/ToList here? Authentication-related actions are probably not critical paths, so I guess the extra allocations are fine.

@Eilon Eilon removed this from the Backlog milestone Mar 15, 2016
@Eilon
Copy link
Member

Eilon commented Mar 15, 2016

Fine, fine, we can take this 😄

var authentication = context.HttpContext.Authentication;
await authentication.SignInAsync(AuthenticationScheme, Principal, Properties);

logger.SignInResultExecuting(AuthenticationScheme, Principal);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally this line would take place before the call to SignInAsync. This way if the 'actual' operation throws, we've already logged what we were trying to do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I'll update that and fix the existing results.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@rynowak
Copy link
Member

rynowak commented Mar 18, 2016

⌚ from me for a few small things

@HaoK - any more feedback on this?

@kevinchalet
Copy link
Contributor Author

(FWIW, that would be great if the authentication helpers had overloads accepting a params string[] argument for authenticationSchemes).

Any opinion?

@HaoK
Copy link
Member

HaoK commented Mar 18, 2016

Looks fine to me :shipit:

@rynowak
Copy link
Member

rynowak commented Mar 23, 2016

@PinpointTownes - any updates?

(FWIW, that would be great if the authentication helpers had overloads accepting a params string[] argument for authenticationSchemes).

I wouldn't block this PR on that item, if you want to, go ahead and file that on the appropriate repo?

@kevinchalet
Copy link
Contributor Author

Sadly no. Fixing all the aspnet-contrib/OpenIddict stuff to make DNX and CLI happy with the recent changes in corefx and NuGet took me much more time than I had expected (and that's an euphemism).

The fact MVC itself no longer compiles with DNX/VS is also extremely annoying, specially since CLI no longer works on Windows 7: https://github.com/dotnet/cli/issues/1966

TBH, I don't feel super comfortable not being able to run the unit tests before pushing new commits. But since you haven't updated MVC to include the frameworkAssemblies workaround that would make DNX happy and since CI builds always fail before running the tests, that's pretty much my only option.

I'll try some yolodev tonight and fix all the reviewed points.

By authentication helpers, I meant the SignOut/Challenge/Forbid methods exposed by ControllerBase, that all take IList. We could update them to take array params without having to update AuthenticationManager.

Le 23 mars 2016 à 17:50, Ryan Nowak [email protected] a écrit :

@PinpointTownes - any updates?

(FWIW, that would be great if the authentication helpers had overloads accepting a params string[] argument for authenticationSchemes).

I wouldn't block this PR on that item, if you want to, go ahead and file that on the appropriate repo?


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub

@rynowak
Copy link
Member

rynowak commented Mar 23, 2016

By authentication helpers, I meant the SignOut/Challenge/Forbid methods exposed by ControllerBase, that all take IList. We could update them to take array params without having to update AuthenticationManager.

Yeah I think that would be a fine change

Sorry for all the difficulties 😢 if you don't manage to get to this I'm happy to fix up the remaining stuff and make sure sure it's included for RC2.

var authentication = context.HttpContext.Authentication;
if (AuthenticationSchemes.Count > 0)
if (AuthenticationSchemes != null && AuthenticationSchemes.Count > 0)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a null check here, since AuthenticationSchemes can be null (there's no null guard in the constructor).

@kevinchalet
Copy link
Contributor Author

📅 PR updated 😄

@kevinchalet
Copy link
Contributor Author

Yeah I think that would be a fine change

Alright, I've updated the ControllerBase methods but kept the results themselves as-is (they still take IList<string> parameters)

Sorry for all the difficulties 😢 if you don't manage to get to this I'm happy to fix up the remaining stuff and make sure sure it's included for RC2.

No worries. Thanks for the offer: actually, it would be great if you could run the tests for me 😄

if (authenticationSchemes.Count == 0)
{
// TODO: move the exception message to the resources file.
throw new ArgumentException("At least one scheme must be specified", nameof(authenticationSchemes));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take a look at fixing this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum, are you commenting on an old commit? I'm pretty sure I've fixed that (by manually adding the resource entry :trollface:)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that was an oopsie on my part

@rynowak
Copy link
Member

rynowak commented Mar 23, 2016

:shipit: - looks good to me. I'm going to squash and run tests for you

@kevinchalet
Copy link
Contributor Author

I can squash it if you want, it will be easier for you if you want to cherry-pick it.

@rynowak
Copy link
Member

rynowak commented Mar 23, 2016

go for it then 👍

@kevinchalet
Copy link
Contributor Author

Done 👏

@rynowak
Copy link
Member

rynowak commented Mar 23, 2016

Will merge as soon as I'm able to.... (restore issues). #ThanksPranav

@rynowak
Copy link
Member

rynowak commented Mar 24, 2016

Still waiting on package/build issues, will update once I've been able to merge.

@kevinchalet
Copy link
Contributor Author

Thanks!

Yeah, it's super messy ATM, the reversioning of the new System.Runtime package is literally killing me (openiddict/openiddict-core#76 (comment))

@rynowak
Copy link
Member

rynowak commented Mar 28, 2016

Pushed as f9d24a8 Thanks 👍

@rynowak rynowak closed this Mar 28, 2016
@kevinchalet kevinchalet deleted the signin_signout_results branch March 28, 2016 20:19
@kevinchalet
Copy link
Contributor Author

Thanks @rynowak 👏 👏

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants