All Projects → bleeding182 → auth

bleeding182 / auth

Licence: MIT License
Get started with the Android Authentication Framework!

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to auth

Vulnerable-OAuth-2.0-Applications
vulnerable OAuth 2.0 applications: understand the security implications of your OAuth 2.0 decisions.
Stars: ✭ 224 (+700%)
Mutual labels:  oauth
Authl
A library for managing federated identity
Stars: ✭ 20 (-28.57%)
Mutual labels:  oauth
MrHuo.OAuth
.netcore 下最好用的第三方登录组件集合,集成了国内外大部分平台,欢迎使用。
Stars: ✭ 152 (+442.86%)
Mutual labels:  oauth
WooDroid
Simple, robust Woocommerce API sdk for java and android
Stars: ✭ 77 (+175%)
Mutual labels:  oauth
twothy
Two factor authenticator for CLI
Stars: ✭ 39 (+39.29%)
Mutual labels:  authenticator
youtube-deno
A Deno client library of the YouTube Data API.
Stars: ✭ 30 (+7.14%)
Mutual labels:  oauth
goth fiber
Package goth_fiber provides a simple, clean, and idiomatic way to write authentication packages for fiber framework applications.
Stars: ✭ 26 (-7.14%)
Mutual labels:  oauth
rust-oauthcli
Yet Another OAuth 1.0 Client Library for Rust
Stars: ✭ 15 (-46.43%)
Mutual labels:  oauth
redux-oauth
Bearer token-based authentication library with OAuth2 support for redux applications.
Stars: ✭ 68 (+142.86%)
Mutual labels:  oauth
verdaccio-github-oauth-ui
📦🔐 GitHub OAuth plugin for Verdaccio
Stars: ✭ 56 (+100%)
Mutual labels:  oauth
legacy-api-documentation
This is the 500px API documentation.
Stars: ✭ 19 (-32.14%)
Mutual labels:  oauth
github-oauth-plugin
Jenkins authentication plugin using GitHub OAuth as the source.
Stars: ✭ 97 (+246.43%)
Mutual labels:  oauth
OpenAM
OpenAM is an open access management solution that includes Authentication, SSO, Authorization, Federation, Entitlements and Web Services Security.
Stars: ✭ 476 (+1600%)
Mutual labels:  oauth
mastodon-api-php
PHP wrapper for the Mastodon API.
Stars: ✭ 12 (-57.14%)
Mutual labels:  oauth
oauth
OAuth library for nim
Stars: ✭ 54 (+92.86%)
Mutual labels:  oauth
httpx-oauth
Async OAuth client using HTTPX
Stars: ✭ 55 (+96.43%)
Mutual labels:  oauth
Updoot
A reddit client built for android
Stars: ✭ 51 (+82.14%)
Mutual labels:  oauth
appleauth-net
AppleAuth.NET is a simple library that facilitates the implementation of "Sign in with Apple" for .NET applications.
Stars: ✭ 23 (-17.86%)
Mutual labels:  oauth
lumen-api-skeleton
Lumen API skeleton with JWT to manager tokens, Socialite to OAuth Providers, MongoDB driver and Predis to Redis cache storage.
Stars: ✭ 22 (-21.43%)
Mutual labels:  oauth
lsso
Nginx SSO middleware for protecting your internets.
Stars: ✭ 42 (+50%)
Mutual labels:  oauth

Auth—Wrapper for the Authentication Framework

Provides a tested implementation for the Android Account Framework for you to get rid of SharedPreference based authentication.

Why not SharedPreferences?

SharedPreferences work well and will be good enough for most projects, but there are 2 edge cases that don't always work as expected.

  1. Clear Data in the apps settings will remove any app data—including your OAuth tokens!
  2. When triggering a token refresh after an access token has expired some APIs invalidate your refresh token (one time use). When refreshing the token at the same time from multiple threads you might receive 401 on your later requests, possibly logging out your user. Even if your API can handle multiple requests, this library will only ever send one token refresh request at a time.

This library will help provide a stable user experience and may help you save time while testing since you can clean your app data without having to login again.

Why a library?

Implementing the Account Manager Framework needs a lot of boilerplate and is a little confusing. To make it more accessible this library provides support for a basic OAuth use case.

Additionally this is intended as an example for you on how to implement your own Authenticator, as the internet is somewhat lacking on that.

Features

As already mentioned above, this library implements (some of) the boilerplate needed to use the Authenticator Framework. The core of it is the OAuthAuthenticator that will be registered on the Android framework and supports single or multi-user applications.

For convenience this library includes a basic OAuthAccountManager that wraps the framework AccountManager and offers a simple single user experience (login, logout, isLoggedIn). This account manager when used with OkHttp also offers RequestAuthInterceptor and RequestRetryAuthenticator which will add the Authorization headers to your HTTP requests and refresh the access token when it becomes invalid.

There is currently no "wrapper" for multi-user support. If you need this make sure to check the above mentioned classes and continue from there!

Usage / Setup

There is an example project in the /app folder that uses the Reddit API and shows how the library could be used. You have to add your own CLIENT_ID if you want to run the example! Take not of the two Retrofit services used (one without authentication, the other one with auth headers) to prevent deadlocks when refreshing the token.

Sadly you will still need to add some boilerplate as you can see next.

Gradle

The library is currently published on my bintray repository, so add the following to the end of your repositories in your root build.gradle file.

repositories {
    maven {
        url "https://dl.bintray.com/bleeding182/bleeding182/"
    }
}

Then include the packages

implementation 'com.davidmedenjak.auth:auth:0.3.0'
implementation 'com.davidmedenjak.auth:auth-okhttp:0.3.0'

The library is currently pre-release. I will publish the artifacts on jcenter/maven central once I have some feedback and am happy with the API

Basic Setup

You start by extending AuthenticatorService and return an implementation of AuthCallback that enables token refreshing. In your AuthCallback you should call your API and trade the refresh token for a new access token.

public class RedditAuthenticatorService extends AuthenticatorService {

    private RedditAuthApi authApiService; // Retrofit service

    @Override
    public AuthCallback getAuthCallback() {
        return new RedditAuthCallback(this, authApiService);
    }
}

Then you add the service to your manifest, registering the AccountAuthenticator.

<service
    android:name=".auth.RedditAuthenticatorService"
    android:permission="android.permission.ACCOUNT_MANAGER">
    <intent-filter>
        <action android:name="android.accounts.AccountAuthenticator"/>
    </intent-filter>
    <meta-data
        android:name="android.accounts.AccountAuthenticator"
        android:resource="@xml/authenticator"/>
</service>

Next you create the xml resource that contains your Authenticators configuration. An example for res/xml/authenticator can be seen here:

<?xml version="1.0" encoding="utf-8"?>
<account-authenticator
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:accountType="@string/account_type"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:smallIcon="@mipmap/ic_launcher"/>

If you want to use the OAuthAccountManager for convenience you should add your account type to your manifest as well. Alternatively you can supply it at runtime.

<application>
    <meta-data android:name="oauth-account.type" android:value="@string/account_type" />
</application>

And that's the basic setup! Be sure to check the example for more information.

OAuthAccountManager - OkHttp

The auth-okhttp package contains an interceptor and an authenticator for OkHttp that will add a Authorization: Bearer {{accessToken}} header to your api calls. To set it up you can use OAuthAccountManager that will fetch the token from the Account Authenticator, or alternatively implement the interface yourself.

AccountAuthenticator authenticator = OAuthAccountManager.fromContext(this);
OkHttpClient okHttpClient =
        new OkHttpClient.Builder()
                .authenticator(new RequestRetryAuthenticator(authenticator))
                .addInterceptor(new RequestAuthInterceptor(authenticator))
                .build();

Contributing

This library will keep a 0.* version until I am happy with the interface and can provide solid support for the most common OAuth use cases with multiple users. As such the current interfaces might change with any update.

Feedback about the usage and API is welcome. When you decide to add a feature request please think about whether this is a common use case that should be handled by this library.

License

MIT License applies, so please feel free to use what you need.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].