Git Product home page Git Product logo

lock.android's Introduction

Note As part of our ongoing commitment to best security practices, we have rotated the signing keys used to sign previous releases of this SDK. As a result, new patch builds have been released using the new signing key. Please upgrade at your earliest convenience.

While this change won't affect most developers, if you have implemented a dependency signature validation step in your build process, you may notice a warning that past releases can't be verified. This is expected, and a result of the key rotation process. Updating to the latest version will resolve this for you.

Lock for Android

CircleCI License Maven Central

πŸ“š Documentation β€’ πŸš€ Getting Started β€’ ⏭️ Next Steps β€’ πŸ’¬ Feedback

Documentation

Getting Started

Requirements

Android API Level 21+ & Java version 8 or above is required in order to use Lock's UI.

Here’s what you need in build.gradle to target Java 8 byte code for the Android and Kotlin plugins respectively.

android {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }
}

Installation

Lock is available in Maven Central. To start using Lock add this line to the dependencies of your build.gradle file:

implementation 'com.auth0.android:lock:3.2.2'

Next Steps

If you haven't done yet, go to Auth0 and create an Account, it's free! Then create a new Application of type Native and add a URL in Allowed Callback URLs with the following format:

https://{YOUR_AUTH0_DOMAIN}/android/{YOUR_APP_PACKAGE_NAME}/callback

The package name value required in the Callback URL can be found in your app's build.gradle file in the applicationId property. Both the domain and client id values can be found at the top of your Auth0 Application's settings. You're going to use them to setup the SDK. It's good practice to add them to the strings.xml file as string resources that you can reference later from the code. This guide will follow that practice.

<resources>
    <string name="com_auth0_client_id">YOUR_AUTH0_CLIENT_ID</string>
    <string name="com_auth0_domain">YOUR_AUTH0_DOMAIN</string>
</resources>

In your app/build.gradle file add the Manifest Placeholders for the Auth0 Domain and Auth0 Scheme properties, which are going to be used internally by the library to declare the Lock activities and register intent-filters that will capture the authentication result.

apply plugin: 'com.android.application'

android {
    compileSdkVersion 30
    defaultConfig {
        applicationId "com.auth0.samples"
        minSdkVersion 21
        targetSdkVersion 30
        //...

        //---> Add the next line
        manifestPlaceholders = [auth0Domain: "@string/com_auth0_domain", auth0Scheme: "https"]
        //<---
    }
    //...
}

The next step is to create an instance of Auth0 with your application's information. The easiest way to create it is by using the values defined previously in the strings.xml file and passing an Android Context. For this to work, you must have defined the string resources using the same keys as listed above.

val account = Auth0(context)

Alternatively, you can directly pass the values.

val account = Auth0("{YOUR_AUTH0_CLIENT_ID}", "{YOUR_AUTH0_DOMAIN}")

Or, if you are using custom domains and are required to specify a different URL to fetch the Lock widget configuration from, you can use the constructor that takes 3 parameters:

val account = Auth0("{YOUR_AUTH0_CLIENT_ID}", "{YOUR_AUTH0_DOMAIN}", "{THE_CONFIGURATION_DOMAIN}")

Email/Password, Enterprise & Social authentication

Initialize Lock and handle the release of its resources appropriately after you're done using it.

// This activity will show Lock
class MyActivity : AppCompatActivity() {

    private lateinit var lock: Lock

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
    
        val account = Auth0(this)
        // Instantiate Lock once
        lock = Lock.newBuilder(account, callback)
            // Customize Lock
            .build(this)
    }
    
    override fun onDestroy() {
        super.onDestroy()
        // Important! Release Lock and its resources
        lock.onDestroy(this)
    }
    
    private val callback = object : AuthenticationCallback() {
        override fun onAuthentication(credentials: Credentials) {
            // Authenticated
        }
        
        override fun onError(error: AuthenticationException) {
            // An exception occurred
        }
    }
}

Start LockActivity from inside your Activity. For this, create a new intent from the Lock instance and launch it.

startActivity(lock.newIntent(this))

Customizing the widget

When using the Builder to instantiate the widget, you can pass different options to customize how it will behave. Some options are only available for Lock or PasswordlessLock. Below you will find a few of them. You can always explore all the available options with your IDE's auto-complete shortcut. Check the Javadocs to understand the default values.

// Create a new builder from Lock or LockPasswordless classes
newBuilder(account, callback)
    // Shared options
    .closable(true) // Allows the widget to be closed with the back button
    .withScope('new-scope') // Changes the scope to be requested on authentication
    .withAudience('my-api') // Changes the audience to be requested on authentication
    .withScheme('myapp') // Changes the scheme part used to generate the Callback URL (more below)
    
    // Lock specific options
    .initialScreen(InitialScreen.SIGN_UP) // Allows to choose the screen to be displayed first 
    .allowLogIn(false) // Disables the Log In screen
    .allowSignUp(false) // Disables the Sign Up screen
    .allowForgotPassword(false) // Disables the Change Password screen
    .setDefaultDatabaseConnection('my-connection') // When multiple are available, select one
    
    // PasswordlessLock specific options
    .useCode(true)  // Requests to receive a OTP that will need to be filled in your android app to authenticate the user
    .useLink(false) // Requests to receive a link that will open your android app to authenticate the user
    .rememberLastLogin(true) // Saves the email or phone number to avoid re-typing it in the future
    
    // Build the instance
    .build(this)

Feedback

Contributing

We appreciate feedback and contribution to this repo! Before you get started, please see the following:

Raise an issue

To provide feedback or report a bug, please raise an issue on our issue tracker.

Vulnerability Reporting

Please do not report security vulnerabilities on the public Github issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.


Auth0 Logo

Auth0 is an easy to implement, adaptable authentication and authorization platform. To learn more checkout Why Auth0?

This project is licensed under the MIT license. See the LICENSE file for more info.

lock.android's People

Contributors

blake-carrier avatar bryant1410 avatar carlosgub avatar cocojoe avatar damieng avatar evansims avatar fossabot avatar frederikprijck avatar gy741 avatar horsejockey avatar hzalaz avatar ivabra avatar joshcanhelp avatar lbalmaceda avatar luisrudge avatar morganlutz avatar nikolaseu avatar poovamraj avatar ruturaj123 avatar skrabacz-michal avatar spaszahariev avatar sre-57-opslevel[bot] avatar stevehobbsdev avatar vincentjoshuaet avatar vyaspranjal33 avatar widcket avatar ziluvatar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lock.android's Issues

Show error message returned from a rule

When trying to authenticate a user and a Rule returns an error like:

{
  "error": "unauthorized",
  "error_description": "You need to count to 10 before you can access this application."
}

Show the content of error_description to the user.

Email Signup does not close window on success

When I sign up using a new email address, I enter new credentials, click the 'sign up' button, and it shows a progress indicator.

In the Auth0 console I can see that the signup was a success, but the app does not seem to recognize, it never leaves the 'in progress' state.

When I hit the backbutton I get back to the login screen, and logging in using the new credentials logs me in perfectly.

Sign Up should show the social buttons

If I'm not mistaken, Lock.js displays the social buttons when displaying the Sign Up panel. I think Lock.Android should do the same, as most users tend to click on Sign Up the first time and won't ever then sign up using G+ for example.

Properly handle configuration URL

Configuration url should:

  • Accept either a full URL e.g.: https://my-config-domain.com
  • Build full URL from domain name e.g.: my-config-domain.com should get https://my-config-domain.com

Also the app configuration should be based in configuration url and have the following format: <config -url>/client/<client_id>.js

Google+ signup fails after revoking app's rights.

I have an app that uses Google+ signup. This works, it asks which account i want to use, I select the one present, I get the google dialog asking for permission, i hit ok. All fine.

Then I close my app, and in the Google+ app I revoke the rights of my app.

I would expect the same procedure as before to be run, asking me for permission.
Instead, I get the following screen:
device-2015-05-21-152941

Logcat:

05-21 15:17:15.369 12225-12225/E/com.auth0.googleplus.GooglePlusIdentityProviderοΉ• Connection failed with unrecoverable error
05-21 15:17:15.369 12225-12225/ E/com.auth0.lock.LockActivityοΉ• Failed to authenticate user
05-21 15:17:15.369 12225-12225/ E/com.auth0.googleplus.GooglePlusIdentityProviderοΉ• Failed to clear G+ Session
java.lang.IllegalStateException: GoogleApiClient must be connected.
at com.google.android.gms.common.internal.zzv.zza(Unknown Source)
at com.google.android.gms.plus.Plus.zzf(Unknown Source)
at com.google.android.gms.internal.zzll.clearDefaultAccount(Unknown Source)
at com.auth0.googleplus.GooglePlusIdentityProvider.clearSession(GooglePlusIdentityProvider.java:108)
at com.auth0.lock.LockActivity.onAuthenticationError(LockActivity.java:221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.squareup.otto.EventHandler.handleEvent(EventHandler.java:89)
at com.squareup.otto.Bus.dispatch(Bus.java:384)
at com.squareup.otto.Bus.dispatchQueuedEvents(Bus.java:367)
at com.squareup.otto.Bus.post(Bus.java:336)
at com.auth0.lock.identity.LockIdentityProviderCallback.onFailure(LockIdentityProviderCallback.java:62)
at com.auth0.googleplus.GooglePlusIdentityProvider.onConnectionFailed(GooglePlusIdentityProvider.java:147)
at com.google.android.gms.common.internal.zzj.zzj(Unknown Source)
at com.google.android.gms.common.api.zze.zzf(Unknown Source)
at com.google.android.gms.common.api.zze.zzc(Unknown Source)
at com.google.android.gms.common.api.zze.zzc(Unknown Source)
at com.google.android.gms.common.api.zze$zza$1.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5696)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)

using:
compileSdkVersion 21
buildToolsVersion "22.0.1"
compile 'com.auth0.android:lock:1.7.0'
compile 'com.auth0.android:lock-googleplus:1.7.0'
compile 'com.google.android.gms:play-services-plus:7.3.0'

Change Password

Part of #11

  • Fragment
  • Perform Request
  • Validate Fields
  • Show alert after sending request
  • Custom error handling

Refresh token null

Hello,

The property refreshToken is coming null from token on object received in authentication callback.

Without refreshToken can not revalidate the authentication if it is expired, right?

Authentication Callback is showing invalid webpage for the callback url

I have set the options per the documentation but I am receiving an issue with the callback.

The webpage at a0HTQWQV982MouCiNzVXXhoIzpbQc://tenant.auth0.com/authorize................

Could not be found.

Any ideas what I am missing. In the past when rolling my own providers I had to check for the callback url in order to extract the token. Does the callback url need to be set or any other configuration set. I don't see this as an option.

Move social integrations to an independent pod

This will fix #64.

The projects we'll have are:

  • com.auth0.android:lock-facebook
  • com.auth0.android:lock-googleplus

We only need to have a different version for each of them, instead of a general version for everything.

G+ native auth should use the minimal scope

I'm comparing the Android native and web Google OAuth integration, and found out that using the web integration, the user is asked to enable our app to access its profile and email (minimal requirements) and using the native integration, the user is asked for this + access to his/her G+ circles, posting app-related info to its "timeline".

Could the native auth be downgraded to using the bare minimum G+ scope?

Many thanks!

DB Authentication

  • Login with email/password
  • Sign Up with email/password
  • Reset password

GPlus native integration

I'm trying to integrate native authentication with GPlus, but is not working to me.

compile 'com.auth0.android:lock:1.1.+'
compile 'com.auth0.android:lock-googleplus:1.1.+'
  • Added proGuardFiles on gradle file
buildTypes {
  release {
    minifyEnabled true
    proguardFile '../proguard/proguard-google-play-services.pro' //G+ native auth
    proguardFile '../proguard/proguard-android-async-http.pro' //Auth0 core
    proguardFile '../proguard/proguard-jackson-2.pro' //Auth0 core
    proguardFile '../proguard/proguard-square-otto.pro' //Lock
    proguardFile '../proguard/proguard-lock.pro' //Lock
    //Add your app's specific proguard rules
  }  
  • I implemented the GoogleApiClient connection and Lock scaffolding on my Activity
// WelcomeActivity.java
package com.squidit.activities;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.View;

import com.auth0.core.Token;
import com.auth0.core.UserProfile;
import com.auth0.lock.Lock;
import com.auth0.lock.LockActivity;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.plus.Plus;
import com.squidit.fragments.LoginSlideFragment;
import com.squidit.squid.R;

import java.util.ArrayList;


public class WelcomeActivity extends FragmentActivity {

    private GoogleApiClient mGoogleApiClient;
    private LocalBroadcastManager broadcastManager;
    private BroadcastReceiver authenticationReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            UserProfile profile = intent.getParcelableExtra("profile");
            Token token = intent.getParcelableExtra("token");
            Log.i("LockLog", "User " + profile.getName() + " logged in");
            goToMainActivity();
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);

        Plus.PlusOptions options = new Plus.PlusOptions.Builder()
                .addActivityTypes("http://schemas.google.com/AddActivity",
                        "http://schemas.google.com/ReviewActivity")
                .build();

        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addApi(Plus.API, options)
                .addScope(Plus.SCOPE_PLUS_LOGIN)
                .build();

        broadcastManager = LocalBroadcastManager.getInstance(this);
        broadcastManager.registerReceiver(authenticationReceiver, new IntentFilter(Lock.AUTHENTICATION_ACTION));
    }

    @Override
    protected void onStart() {
        super.onStart();
        mGoogleApiClient.connect();
    }

    @Override
    protected void onStop() {
        mGoogleApiClient.disconnect();
        super.onStop();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        broadcastManager.unregisterReceiver(authenticationReceiver);
    }

    @Override
    public void onBackPressed() {
            super.onBackPressed();
    }

    private void goToMainActivity(){
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
    }

    public void enter(View view){
        Intent lockIntent = new Intent(this, LockActivity.class);
        startActivity(lockIntent);
    }

}
  • Implemented an Application to initialize Lock
// SquidApplication.java
package com.squidit.application;

import android.app.Application;

import com.auth0.core.Strategies;
import com.auth0.facebook.FacebookIdentityProvider;
import com.auth0.googleplus.GooglePlusIdentityProvider;
import com.auth0.lock.Lock;
import com.auth0.lock.LockBuilder;
import com.auth0.lock.LockProvider;

public class SquidApplication extends Application implements LockProvider {

    private Lock lock;

    public void onCreate() {
        super.onCreate();
        lock = new LockBuilder()
                .loadFromApplication(this)
                .closable(true)
                .build();

        FacebookIdentityProvider facebook = new FacebookIdentityProvider();
        GooglePlusIdentityProvider googleplus = new GooglePlusIdentityProvider(this);

        lock.setProvider(Strategies.GooglePlus.getName(), googleplus);
        lock.setProvider(Strategies.Facebook.getName(), facebook);
    }

    @Override
    public Lock getLock() {
        return lock;
    }
}
  • Configured Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.squidit.squid">

    <!-- To auto-complete the email text field in the login form with the user's emails -->
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.READ_PROFILE" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.USE_CREDENTIALS" />
    <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

    <application
        android:name="com.squidit.application.SquidApplication"
        android:allowBackup="true"
        android:icon="@drawable/ic_squid"
        android:label="@string/app_name"
        android:theme="@style/DefaultTheme"
        tools:replace="android:icon">
        <activity
            android:name="com.squidit.activities.WelcomeActivity"
            android:label="@string/app_name"
            android:theme="@style/DefaultTheme" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <!--Auth0 Lock-->
        <activity
            android:name="com.auth0.lock.LockActivity"
            android:theme="@style/Lock.Theme"
            android:screenOrientation="portrait"
            android:launchMode="singleTask">
            <intent-filter>
                <action android:name="android.intent.action.VIEW"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <category android:name="android.intent.category.BROWSABLE"/>
                <data android:scheme="a0MY_AUTH0_CLIENT_ID" android:host="MY_AUTH0_DOMAIN.auth0.com"/>
            </intent-filter>
        </activity>
        <meta-data android:name="com.auth0.lock.client-id" android:value="@string/auth0_client_id"/>
        <meta-data android:name="com.auth0.lock.tenant" android:value="@string/auth0_tenant_name"/>
        <!--Auth0 Lock End-->
        <activity
            android:name="com.squidit.activities.MainActivity"
            android:label="@string/title_activity_main" >
        </activity>
        <activity android:name="com.facebook.LoginActivity"/>
        <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
    </application>

</manifest>

Buuut, throws an exception in Android Studio when i try to login with GPlus:

com.auth0.googleplus.GooglePlusIdentityProvider: Connection failed with unrecoverable error
com.auth0.lock.LockActivity: Failed to authenticate user
com.auth0.googleplus.GooglePlusIdentityProvider: Failed to clear G+ Session.
java.lang.IllegalStateException: GoogleApiClient must be connected

And on the android application:

screenshot_2015-02-18-22-02-13

What I'm doing wrong?

There session authentication? how should I implement?

I'm using the Auth0 for authentication, very good.

I would Info if there is something in the library or any tips on how to implement a session in the application.

Example in the second time you open the application, start automatically authenticated.

LockActivity is blank on Android 5.0.1 Lollipop

I'm using the sample android application, the authentication activity (LockActvity) is launching successfully but the the activity is blank when only using the Username-Password-Authentication provider. Initially you see the Auth0 logo but it disappears. If I enable a social provider such as G+ the login fields appear.

Social Login - Google Plus(non native) fails to return from browser

I'm using Lock 1.5 with Google plus and DB authentication. When tapping the G+ icon to login the default browser opens up. I tap the account I want to use but the page reloads and doesn't return to the app. I can see from the Auth0 console that authentication has been successful. What is the expected flow?

Lock options

  • Default authentication parameters
  • Enable/Disable signUp + Login
  • Cancel Event
  • Disable back navigation
  • Enable Username

Better handling of app info fetch errors

  • Allow to retry when the request to fetch the app info fails
  • Show No Connection error. (We might need an extra permission)
  • Detect invalid Auth0 configuration (e.g. Invalid ClientID, domain)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.