OAuth2Library


Source link: https://github.com/AliAbozaid/OAuth2Library

OAuth2Library

OAuth2Library is an extension for Retrofit that simplifies the process of authenticating against an OAuth 2 provider.

Authentication

OAuthToken oAuthToken = new OAuthToken("http://www.yoururl.com/","abozaid","1234567", this);
 
  1. Base URL.
  2. Client ID.
  3. Secret key.

Authorizing Request

Credential credential = oAuthToken.getAccessTokenWithID("default");

If you want to use our default send parameter “default” if not send your keys.

 if(credential == null || credential.getAccess_token()==null)

{

 oAuthToken.AuthentiacteUsingOAuth("v1/api/oauth", "5592b3be0cf2921ec587d5",

"935eadc6-cd58-4743-8f14-5f7af391c992", "read write", "password",

new MethodsCallback<Credential>()

{

 @Override public void failure(Throwable throwable)

 {

  Toast.makeText(MainActivity.this, arg0.getMessage(),Toast.LENGTH_SHORT).show();

 
}

 @Override public void success(Credential credential)

 {

  if(credential != null)

  {

oAuthToken.saveTokenWithID(arg0, "default");

Toast.makeText(MainActivity.this, arg0.getAccess_token(), Toast.LENGTH_SHORT).show();

  
}

 
}

 @Override void responseBody(Call<T> call)

 {

}

}
);

}
 

We first check our credential if it does not exist we call (AuthentiacteUsingOAuth) method to authenticate and here is it’s parameters:

  1. path URL, and here we follow the standards., if your backend developer follow it, all you need is to put your path url except for (/token). if not, you need to clone the repo and import it as a module and change the URL.
  2. UserName, your username returned from the server after the registration process.
  3. Password, your password returned from the server after the registration process.
  4. Scope, it will be one of three choices(read, write, read write).
  5. Grant type, it will be one of three choices(password, authorization_code, client_credential, refresh_token).
  6. Response callback.

Storing Credentials

if our credential returned in success method we call (saveTokenWithID) method and we pass the credential object and our id (“default”, or your id ).

Refreshing Credentials

Before any call to the server we call (isExpired(id)) method, if it returns false we do our call but if it returns true that means that we need to refresh our token so we need to call (refreshToken()) method and it’s parameter:

  1. Path URL, same as in (AuthentiacteUsingOAuth)method path url except for (/token).
  2. Refresh token, get it by calling(getRefreshTokenWithId(id)) after storing it in (AuthentiacteUsingOAuth) method.
  3. Response callback. also you need to call (saveTokenWithID) method in success method to save your new credentials.

Delete Credentials

There is Two Methods To delete your Credential

  1. deleteAllToken().
  2. deleteTokenWithId(id), your id or “default”.

Others Method

  1. getAccessTokenWithId(id) return Credential object.
  2. getTokenwithId(id) return Token String.
  3. getRefreshTokenWithId(id) return RefreshToken String.
  4. getExpiryDateWithId(id) return expiryDate Long.

Gradle

add this in repositories

maven {

  url 'https://dl.bintray.com/abozaid/maven'
 
}
 

and this in dependencies

compile 'com.github.aliabozaid.oauth2library:OAuth2Library:0.0.3’ 

License

Copyright 2013 Square, Inc.  Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License. You may obtain a copy of the License at
  http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 

Resources

Mortar / Flow / Dagger 2 requires to write a lot of boilerplate code. Auto Mortar is an annotation processor that focuses on eliminating the maximum of that boilerplate. No magic tricks here, just some straightforward and human readable code generated for you.

Introducing Volley Ball for Android, an extension library built on top of Volley.

A simple Android Application which works with PushBullet, helps you to get details of a Channel and allow you to subscribe/unsubscribe.

Alternative for the Google's Drawer Layout.

Swift-CC is a python script that simplifies the compiling of Swift and Objective-C(++) code into object files. It is a two stage wrapper for clang and the swift compiler that uses the Android NDK tools to produce android compatible .o files.

Fit Chart is an Android view similar to Google Fit circular chart.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes