Giter Site home page Giter Site logo

lets-the-right-one-in's Introduction

Lets the Right One In

Lets the Right One In (paraphrase of the excellent novel and movie) or lroi for short is an Android library that provides authentication for services based on Guja.

Features:

  • Compatible with Guja
  • Provides authentication based on AccountManager accounts.
  • Currently supports the OAuth 2.0 Client Credentials Grant flow
  • Aimed for projects that uses Retrofit + OkHttp (unsuitable for projects that don't). This might change in future releases.

Usage

Follow the steps below to use this library. There's also a very basic example app in the /sample folder (please note that this sample doesn't make use of the com.squareup.okhttp.Authenticator and retrofit.RequestInterceptor classes that AuthAdapter can provide).

Step 1

Add the following to your build file.

If you're using gradle:

repositories {
  maven {
    url "https://jitpack.io"
  }
}

dependencies {
  compile 'com.github.Wadpam:lets-the-right-one-in:v0.1.0'
}

If maven is your thing:

<repository>
  <id>jitpack.io</id>
  <url>https://jitpack.io</url>
</repository>

<dependency>
  <groupId>com.github.Wadpam</groupId>
  <artifactId>lets-the-right-one-in</artifactId>
  <version>v0.1.0</version>
</dependency>

Step 2

Create a class that extends se.leiflandia.lroi.auth.AuthenticationService.

Step 3

Add the service created in the last step to the manifest under <application>:

<service
    android:name=".ExampleAuthenticationService"
    android:exported="false"
    android:process=":auth" >
    <intent-filter>
        <action android:name="android.accounts.AccountAuthenticator" />
    </intent-filter>
    <meta-data
        android:name="android.accounts.AccountAuthenticator"
        android:resource="@xml/authenticator" />
</service>

Replace .ExampleAuthenticationService with your own implementation of se.leiflandia.lroi.auth.AuthenticationService.

Step 4

Create the file res/xml/authenticator.xml with the following content:

<?xml version="1.0" encoding="utf-8"?>
<!-- Please note accountType needs to be the same as provided to AuthAdapter -->
<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
    android:accountType="[Insert your account type here]"
    android:icon="@drawable/ic_launcher"
    android:smallIcon="@drawable/ic_launcher"
    android:label="[Insert your account label here]"
    />

Replace the values in brackets.

Step 5

Create an instance of AuthAdapter, for example like this:

AuthAdapter auth = new AuthAdapter.Builder()
    .setAuthTokenType("org.example.account")
    .setAccountType("org.example.account")
    .setEndpoint("https://example.org")
    .setApplicationContext(this)
    .setClientCredentials(new ClientCredentials("clientId", "clientSecret"))
    .setLoginActivityClass(LoginActivity.class)
    .build();

Step 6

Use the instance of Authadapter to perform sign up, sign in and sign out operations. It can also create instances of com.squareup.okhttp.Authenticator and retrofit.RequestInterceptor that can be used together with OkHttp and Retrofit to automatically include the access token in http requests and refresh when access token have expired.

lets-the-right-one-in's People

Contributors

loveleif avatar mattiaslevin avatar

Stargazers

 avatar

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.