com.auth0.lock.Lock Java Examples
The following examples show how to use
com.auth0.lock.Lock.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LoginActivity.java From AvI with MIT License | 6 votes |
@Override public void onReceive(Context context, Intent intent) { userProfile = intent.getParcelableExtra(Lock.AUTHENTICATION_ACTION_PROFILE_PARAMETER); token = intent.getParcelableExtra(Lock.AUTHENTICATION_ACTION_TOKEN_PARAMETER); logTokens(userProfile, token); UserInfo userInfo = new UserInfo(); userInfo.setName(userProfile.getName()); userInfo.setEmail(userProfile.getEmail()); userInfo.setPictureUrl(userProfile.getPictureURL()); userInfo.setAuthId(userProfile.getId()); AccessToken accessToken = new AccessToken(); accessToken.setIdToken(token.getIdToken()); accessToken.setRefreshToken(token.getRefreshToken()); accessToken.setAccessToken(token.getAccessToken()); authenticateFirebase(token.getIdToken()); navigateToNavigationActivity(accessToken, userInfo, false); }
Example #2
Source File: ProfileActivity.java From endpoints-samples with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_profile); UserProfile profile = getIntent().getParcelableExtra(Lock.AUTHENTICATION_ACTION_PROFILE_PARAMETER); Token token = getIntent().getParcelableExtra(Lock.AUTHENTICATION_ACTION_TOKEN_PARAMETER); TextView greetingTextView = (TextView) findViewById(R.id.welcome_message); greetingTextView.setText("Welcome " + profile.getName()); ImageView profileImageView = (ImageView) findViewById(R.id.profile_image); if (profile.getPictureURL() != null) { ImageLoader.getInstance().displayImage(profile.getPictureURL(), profileImageView); } client = new AsyncHttpClient(); client.addHeader("Authorization", "Bearer " + token.getIdToken()); Button callAPIButton = (Button) findViewById(R.id.call_api_button); callAPIButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { callAPI(); } }); }
Example #3
Source File: LockReactModule.java From react-native-lock with MIT License | 6 votes |
/** * This method is exported to JS but no used directly by the user. See auth0-lock.js * Called from JS to configure the {@link com.auth0.lock.Lock.Builder} that will be used to * initialize the {@link com.auth0.lock.Lock} instance. * * @param options the map with the values passed when invoked from JS. Some of the supported * fields are "clientId", "domain" and "configurationDomain" * @see com.auth0.lock.react.bridge.InitOptions */ @ReactMethod public void init(ReadableMap options) { InitOptions initOptions = new InitOptions(options); Telemetry telemetry = new Telemetry("lock.react-native.android", initOptions.getLibraryVersion(), com.auth0.lock.BuildConfig.VERSION_NAME, null); lockBuilder = new Lock.Builder() .useWebView(!initOptions.useBrowser()) .telemetry(telemetry) .clientId(initOptions.getClientId()) .domainUrl(initOptions.getDomain()) .configurationUrl(initOptions.getConfigurationDomain()); if (providers != null) { for (Strategies strategy : providers.keySet()) { lockBuilder.withIdentityProvider(strategy, providers.get(strategy)); } } }
Example #4
Source File: LockReactModuleTest.java From react-native-lock with MIT License | 6 votes |
@Test public void shouldCancelAuthentication() throws Exception { module.init(initOptions("CLIENT_ID", "samples.auth0.com", null)); module.show(null, callback); Intent result = new Intent(Lock.CANCEL_ACTION); module.authenticationReceiver.onReceive(reactContext, result); ArgumentCaptor<Object> captor = ArgumentCaptor.forClass(Object.class); verify(callback).invoke(captor.capture()); List<Object> list = captor.getAllValues(); assertThat((String) list.get(0), is(equalTo(LockReactModule.MESSAGE_USER_CANCELLED))); assertThat(list.get(1), is(nullValue())); assertThat(list.get(2), is(nullValue())); verifyNoMoreInteractions(callback); }
Example #5
Source File: LockReactModuleTest.java From react-native-lock with MIT License | 6 votes |
@Test public void shouldNotifySignUp() throws Exception { module.init(initOptions("CLIENT_ID", "samples.auth0.com", null)); module.show(null, callback); Intent result = new Intent(Lock.AUTHENTICATION_ACTION); module.authenticationReceiver.onReceive(reactContext, result); ArgumentCaptor<Object> captor = ArgumentCaptor.forClass(Object.class); verify(callback).invoke(captor.capture()); List<Object> list = captor.getAllValues(); assertThat((String) list.get(0), is(equalTo(LockReactModule.MESSAGE_USER_SIGNED_UP))); assertThat(list.get(1), is(nullValue())); assertThat(list.get(2), is(nullValue())); verifyNoMoreInteractions(callback); }
Example #6
Source File: LoginActivity.java From AvI with MIT License | 5 votes |
private void instantiateRequiredObjectsForLogin(){ LockContext.configureLock( new Lock.Builder() .loadFromApplication(getApplication()) .closable(true)); final LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(getApplicationContext()); broadcastManager.registerReceiver(receiver, new IntentFilter(Lock.AUTHENTICATION_ACTION)); }
Example #7
Source File: SampleApplication.java From endpoints-samples with Apache License 2.0 | 5 votes |
@Override public void onCreate() { super.onCreate(); lock = new Lock.Builder() .loadFromApplication(this) .withIdentityProvider(Strategies.Facebook, new FacebookIdentityProvider(this)) .build(); ImageLoaderConfiguration configuration = new ImageLoaderConfiguration.Builder(this).build(); ImageLoader.getInstance().init(configuration); }
Example #8
Source File: LockReactModuleTest.java From react-native-lock with MIT License | 5 votes |
@Test public void shouldAuthenticateSuccessfully() throws Exception { module.init(initOptions("CLIENT_ID", "samples.auth0.com", null)); module.show(null, callback); Map<String, Object> values = new HashMap<>(); values.put("user_id", "user-id-value"); values.put("name", "name-value"); values.put("extra_key", "extra-key-value"); UserProfile profile = new UserProfile(values); Token token = new Token("id-token", "access-token", "token-type", "refresh-token"); Intent result = new Intent(Lock.AUTHENTICATION_ACTION) .putExtra(Lock.AUTHENTICATION_ACTION_PROFILE_PARAMETER, profile) .putExtra(Lock.AUTHENTICATION_ACTION_TOKEN_PARAMETER, token); module.authenticationReceiver.onReceive(reactContext, result); UserProfileBridge profileBridge = new UserProfileBridge(profile); TokenBridge tokenBridge = new TokenBridge(token); ArgumentCaptor<Object> captor = ArgumentCaptor.forClass(Object.class); verify(callback).invoke(captor.capture()); List<Object> list = captor.getAllValues(); assertThat(list.get(0), is(nullValue())); assertThat((WritableMap) list.get(1), is(equalTo(profileBridge.toMap()))); assertThat((WritableMap) list.get(2), is(equalTo(tokenBridge.toMap()))); verifyNoMoreInteractions(callback); }
Example #9
Source File: LoginActivity.java From AvI with MIT License | 4 votes |
private void authenticateFirebase(String idToken){ Lock lock = LockContext.getLock(this); if(lock == null){ LockContext.configureLock( new Lock.Builder() .loadFromApplication(getApplication()) .closable(true)); lock = LockContext.getLock(this); } AuthenticationAPIClient client = lock.getAuthenticationAPIClient(); String apiType = "firebase"; String token = idToken; //Your Auth0 id_token of the logged in User Map<String, Object> parameters = ParameterBuilder.newEmptyBuilder() .set("id_token", token) .set("api_type", apiType) .asDictionary(); final AppCompatActivity thisActivity = this; //Auth0 Delegation client.delegation() .addParameters(parameters).start(new BaseCallback<Map<String, Object>>() { @Override public void onSuccess(Map<String, Object> payload) { //Your Firebase token will be in payload Log.i("smuk", "Logged in Firebase via Auth0"); FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(); firebaseAuth.signInWithCustomToken((String) payload.get("id_token")) .addOnCompleteListener(thisActivity, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { Log.i("smuk", "firebase signInWithCustomToken:onComplete:" + task.isSuccessful()); if (!task.isSuccessful()) { Log.i("smuk", "firebase failed signInWithCustomToken", task.getException()); } } }); } @Override public void onFailure(Throwable error) { //Delegation call failed Log.i("smuk", "Failed to log in Firebase via Auth0"); } }); }
Example #10
Source File: SampleApplication.java From endpoints-samples with Apache License 2.0 | 4 votes |
@Override public Lock getLock() { return lock; }