AppAuth WebView


Source link: https://github.com/hadiidbouk/AppAuthWebView-Android

AppAuthWebView Android

Using AppAuth-Android with webview .

Installation

Add the library to your dependencies

compile 'com.github.hadiidbouk:AppAuthWebView-Android:1.1.4'

Also add this in your build.gradle (app)

android {

 ...
  defaultConfig {

  ....

manifestPlaceholders = [

  'appAuthRedirectScheme': ''

]

}
  
}
 

And in the project build.gradle



repositories {

 ..

  maven {
 url 'https://jitpack.io' 
}

 
}

}
 
  1. Create your layouts
<RelativeLayout

 xmlns:android="http://schemas.android.com/apk/res/android"

 xmlns:tools="http://schemas.android.com/tools"

 android:layout_width="match_parent"

 android:layout_height="match_parent">

 <WebView

  android:id="@+id/WebView"

  android:layout_width="match_parent"

  android:layout_height="match_parent"/>

 <FrameLayout

  android:id="@+id/LoadingLayout"

  android:layout_width="match_parent"

  android:layout_height="match_parent"

  android:background="@android:color/holo_green_dark">

  <TextView

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:textColor="#FFF"

android:text="Loading .."

android:textSize="30sp"

android:layout_gravity="center"

android:gravity="center"

/>

 </FrameLayout>

 <FrameLayout

  android:id="@+id/ErrorLayout"

  android:layout_width="match_parent"

  android:layout_height="match_parent"

  android:background="@android:color/holo_red_dark"

  >

  <TextView

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="Error"

android:textColor="#FFF"

android:textSize="30sp"

android:layout_gravity="center"

android:gravity="center"

/>

 </FrameLayout>

</RelativeLayout>
  • Error Layout will be visible when there is a error received in webview .
  • Loading Layout will be visible when waiting the page to be loaded.
  1. Create your AppAuthWebViewData
  AppAuthWebViewData data = new AppAuthWebViewData();

  data.setClientId(");
 

 data.setAuthorizationEndpointUri("");
 

 data.setClientSecret("");
 

 data.setDiscoveryUri("n");
 

 data.setRedirectLoginUri("");
 

 data.setRedirectLogoutUri("");
 

 data.setScope("");
 

 data.setTokenEndpointUri("");
 

 data.setRegistrationEndpointUri("");
 

 data.setResponseType("");
 
data.setGenerateCodeVerifier(false);
  1. Implement IAppAuthWebViewListener
 public class MainActivity extends Activity implements IAppAuthWebViewListener {

  .....

@Override public void onUserAuthorize(AuthState authState) {

  Toast.makeText(this, "Token : " + authState.getIdToken(), Toast.LENGTH_SHORT).show();

  finish();

}

@Override public void showConnectionErrorLayout() {

mErrorLayout.setVisibility(View.VISIBLE);

  
}

@Override public void hideConnectionErrorLayout() {

mErrorLayout.setVisibility(View.INVISIBLE);

  
}

@Override public void showLoadingLayout() {

mLoadingLayout.setVisibility(View.VISIBLE);

  
}

@Override public void hideLoadingLayout() {

mLoadingLayout.setVisibility(View.INVISIBLE);

  
}

}

  
  1. Perform Login Request
  @Override

 protected void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);

  setContentView(R.layout.activity_main);

 ....

AppAuthWebView appAuthWebView = new AppAuthWebView

  .Builder()

  .webView(webView)

  .authData(data)

  .listener(this)

  .build();

appAuthWebView.performLoginRequest();

}

Working with tokens and refresh token

To access the id token or the access token you can simply call the static method AppAuthWebView.getAuthState(Context context) to get the authstate object (already saved in shared preferences) and then access what you want in this object.

To Perform a refresh token request you can simply call the static method AppAuthWebView.peroformRefreshTokenRequest(final Context context, AuthState authState, AppAuthWebViewData data) and if the request success the AuthState will be updated in the shared preferences.

If you are using a service in another process

If you want to get the access token from this service you can do the following :

  1. Create your class extends BroadcastReceiver ( example in Kotlin ) :
  override fun onReceive(context: Context?, intent: Intent?) {

 if(intent!!.action.equals(AppAuthWebView.BROADCAST_RECEIVER_ACTION)) {

 val authState : String = intent.getStringExtra(AppAuthWebView.AUTH_STATE_JSON)

 AppAuthWebView.updateAuthState(context,authState)

}

  
}
  
  1. Register to the broadcast by adding this to your manifest :
  <receiver android:name=".MyBroadcastReceiver">
 <intent-filter>
  <action android:name="com.hadiidbouk.AppAuthWebView.AccessTokenAction"/>
 </intent-filter>
</receiver>

Resources

This library provide syncing of SharedPreferences between handheld and wearable.

An Android View widget for displaying GIF animations.

socialize-sdk-android is an Android social sharing SDK for native apps.

Official site: www.getsocialize.com

RushOrm replaces the need for SQL by mapping java classes to SQL tables.

Core features:

  • Custom fields - easily implement custom fields so that any object can be serialized to the database
  • Relationships:
    • One to one
    • One to many, save lists of children
    • Saving a parent object automatically saves it children
  • Files - easily store long text, JSON and bitmaps
  • Upgrading - database upgrading is supported through annotations removing the need for upgrade scripts

android-gesture-detectors is a gesture detector framework for multitouch handling on Android, based on Android's ScaleGestureDetector.

droidQuery is an Android port of jQuery, and is designed to be as syntactically alike as possible in Java.

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