-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #333 from auth0/refactor-provider-resolver
Refactor AuthProviderResolver [Breaking Change]
- Loading branch information
Showing
22 changed files
with
264 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 0 additions & 48 deletions
48
lib/src/main/java/com/auth0/android/lock/provider/AuthProviderResolver.java
This file was deleted.
Oops, something went wrong.
56 changes: 56 additions & 0 deletions
56
lib/src/main/java/com/auth0/android/lock/provider/AuthResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.auth0.android.lock.provider; | ||
|
||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
|
||
import com.auth0.android.provider.AuthHandler; | ||
import com.auth0.android.provider.AuthProvider; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
|
||
/** | ||
* Holds instances of AuthHandlers that can be used to query for AuthProviders given | ||
* a strategy and connection name. | ||
* When no AuthProvider is matched, it will return null | ||
*/ | ||
public final class AuthResolver { | ||
private static List<AuthHandler> authHandlers; | ||
|
||
private AuthResolver() { | ||
} | ||
|
||
/** | ||
* Sets the AuthHandler list to use on this instance. | ||
* | ||
* @param handlers the list of AuthHandlers to use. | ||
*/ | ||
public static void setAuthHandlers(@NonNull List<AuthHandler> handlers) { | ||
authHandlers = new ArrayList<>(handlers); | ||
} | ||
|
||
/** | ||
* Get an AuthProvider that can handle a given strategy and connection name, or null if there are no | ||
* providers to handle them. | ||
* | ||
* @param strategy to handle | ||
* @param connection to handle | ||
* @return an AuthProvider to handle the authentication or null if no providers are available. | ||
*/ | ||
@Nullable | ||
public static AuthProvider providerFor(@Nullable String strategy, @NonNull String connection) { | ||
if (authHandlers == null) { | ||
return null; | ||
} | ||
|
||
AuthProvider provider = null; | ||
for (AuthHandler p : authHandlers) { | ||
provider = p.providerFor(strategy, connection); | ||
if (provider != null) { | ||
break; | ||
} | ||
} | ||
return provider; | ||
} | ||
} |
Oops, something went wrong.