Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor AuthProviderResolver [Breaking Change] #333

Merged
merged 6 commits into from
Sep 19, 2016

Conversation

lbalmaceda
Copy link
Contributor

@lbalmaceda lbalmaceda commented Aug 19, 2016

Previously, the user needed to define it's own AuthProviderResolver when he was notified of authentication events, asking for an AuthProvider given a connectionName. To simplify that, now the user calls the builder passing handlers:

builder. withAuthHandlers(Arrays.asList(new MyHandler(), new FacebookHandler()));

Each handler can decide whether it can or not handle a given strategy/connection name. Because it's a List, the order matters and the first match will return an AuthProvider. If no provider is found, Lock will default to the WebAuthProvider.

This way we can also provide our own handlers in the social native libs.

@lbalmaceda lbalmaceda added this to the 2.0.0-beta.4 milestone Aug 19, 2016
@lbalmaceda lbalmaceda changed the title Refactor AuthProviderResolver Refactor AuthProviderResolver [Breaking Change] Aug 22, 2016
* @return the current builder instance
*/
public Builder withProviderResolver(@NonNull AuthProviderResolver resolver) {
ProviderResolverManager.set(resolver);
public Builder withAuthHandlers(@NonNull List<AuthHandler> handlers) {
Copy link
Member

Choose a reason for hiding this comment

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

Variable args

@lbalmaceda lbalmaceda force-pushed the refactor-provider-resolver branch from fbea2ed to b0d6d87 Compare August 23, 2016 20:06
@hzalaz hzalaz modified the milestones: 2.0.0-beta.5, 2.0.0-beta.4 Aug 24, 2016
@lbalmaceda lbalmaceda force-pushed the refactor-provider-resolver branch from 0cabd4b to 6366748 Compare September 15, 2016 19:07
* a strategy and connection name.
* When no AuthProvider is matched, it will return null
*/
public abstract class AuthResolver {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know what are the best practices for java, but I would have used a regular class with a private constructor instead of an abstract class.

Copy link
Contributor

Choose a reason for hiding this comment

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

and final, if possible

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nikolaseu Both options are good. Although using a private constructor has the advantage of not letting the user to extend the abstract class and instantiate objects. I will change it. 👍

* @return an AuthProvider to handle the authentication or null if no providers are available.
*/
@Nullable
public static AuthProvider providerFor(String strategy, String connection) {
Copy link
Contributor

Choose a reason for hiding this comment

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

since there are nullable/nonnull annotations everywhere, add them here too?

assertThat(resolver, notNullValue());
assertThat(resolver, equalTo(customResolver));
assertThat(AuthResolver.providerFor("", ""), nullValue());
assertThat(AuthResolver.providerFor("a", "a"), is(equalTo(provider)));
Copy link
Contributor

Choose a reason for hiding this comment

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

since the param is a list, maybe test at least two providers? "a" and "b" ?

break;
}
}
return provider;
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe it's simpler this way?

         for (AuthHandler p : authHandlers) {
             final AuthProvider provider = p.providerFor(strategy, connection);
             if (provider != null) {
                 return provider;
             }
         }
         return 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.

I think both are acceptable and clear.. But the one I did has 1 return point at the end, maybe that helps a bit reading the code?

public void onConnectionClicked(String connectionName) {
lockWidget.onSocialLogin(new SocialConnectionEvent(connectionName));
public void onAuthenticationRequest(@NonNull String strategy,@NonNull String connection) {
lockWidget.onSocialLogin(new SocialConnectionEvent(strategy, connection));
Copy link
Contributor

Choose a reason for hiding this comment

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

this is just a comment, but maybe the name of this method should better reflect what it does? now it's clear that an authentication has been requested, but the onSocialLogin is not that clear (onSocialLoginRequest?).

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 agree. 👍

Copy link
Member

Choose a reason for hiding this comment

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

reactions please 😄

@hzalaz hzalaz merged commit 3552d05 into v2 Sep 19, 2016
@hzalaz hzalaz deleted the refactor-provider-resolver branch September 19, 2016 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants