User Tools

Site Tools


developers:peig-api:android

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
developers:peig-api:android [2018/07/04 07:58]
dskrbek [Creating authentication request]
— (current)
Line 1: Line 1:
-====== Developing Android application with ADUCID ====== 
- 
-//See [[https://github.com/aducid-dev/peigapi-android/|DemoBank]] example - [[https://github.com/aducid-dev/peigapi-android/blob/master/demobank/bank/src/main/java/com/aducid/demo/bank/MainFragment.java|MainFragment.java]]// 
- 
-Prerequisites: used external libraries: 
- 
-  * [[https://github.com/loopj/android-async-http|https://github.com/loopj/android-async-http]] 
-  * [[https://github.com/smarek/httpclient-android|https://github.com/smarek/httpclient-android]] 
- 
-ADUCID PEIG API provides simple way how to integrate ADUCID to custom client application. To keep session cookies, PEIG API uses http async client. (getAsyncClient()) 
- 
-===== Creating authentication request ===== 
- 
-  - First create an instance of PEIG API \\ (only one per application object / set of requests) 
-<code java> 
-com.aducid.peig.lib2.PeigAPI peigApi = new com.aducid.peig.lib2.PeigAPI(Context ctx); 
-</code> 
- 
- 
-  - Prepare a handler which is going to be called when PEIG API is finished (see below) 
-  - Call PEIG API method aducidAuthentication (): 
- 
-<code java> 
-peigApi.aducidAuthentication(String url, Handler handler) 
-</code> 
- 
-  * **url**  is address of your **application**  including protocol, e.g. [[https://demobank.aducid.com/demobank|https://demobank.aducid.com/demobank]] 
-  * **handler**  is code that is called to evaluate authentication 
-In your Handler override **handleMessage**  (Message msg) and get the result: 
- 
-<code java> 
-PapiResult result = msg.getData().getParcelable("result"); 
-</code> 
- 
-then evaluate it - see [[developers:peig-api:android#responses|Responses]] 
- 
-===== Responses ===== 
- 
-Your code should evaluate these possible outcomes: 
- 
-I. 
- 
-<code java> 
-if result.isOK() 
-</code> 
- 
-Your session is authenticated 
- 
-In DemoBank, result.gerRedirect() contains link to page with account data 
- 
-II. 
- 
-<code java> 
-else if (result.peigNotInstalled()) 
-</code> 
- 
-PEIG is not installed. To fix it, you can display a dialog and then open GooglePlay to install it: 
- 
-<code> 
-getPapi().installPEIG(getActivity()); 
-</code> 
- 
-III. 
- 
-<code java> 
-else if (result.isNetworkError()) 
-</code> 
- 
-Communication error occurred – either phone has no connectivity or destination cannot be reached (wrong URL or server is not running). 
- 
-IV. 
- 
-<code java> 
-else {other exception / redirect / state} 
-</code> 
- 
-Custom application errors, authentication failed! 
- 
-  * result.getException() contains ADUCID exception, there are possible states: 
-      * result.notAcceptedByUser(): user rejected 
-      * result.isFactorAbsent(): user doesn’t have personal factor (and server requires it) 
-  * result.getData() contains error Message / reason 
-  * result.getRedirect() contains page that could be opened using browser / contains additional content to download/ display to the user. 
- 
-//See PapiResult class for all details// 
- 
-===== Retrieve data when authenticated ===== 
- 
-In case I. your result is “OK” and your mobile application is authenticated. Use this session to contact your application server. AsyncHttpClient is used as http client to keep session cookies and GET/POST/PUT/DELETE operations. Following example shows how to use this client to GET a page when authenticated: 
- 
-<code> 
-getPapi().getAsyncClient().get(String url, RequestParams parameters, ResponseHandlerInterface responseHandler) 
-</code> 
- 
-  * **url**  – target page / method URL, e.g. [[https://demobank.aducid.com/demobank/|https://demobank.aducid.com/demobank/]]**payment** 
-  * **parameters**  – specify https(s) request parameters for your request if needed 
-  * **AsyncHttpResponseHandler**  – callback to be executed when data is loaded 
-==== Try to get data if not authenticated ==== 
- 
-To check your setup, test if you get error response from the server 
- 
-===== Advanced requests ===== 
- 
-To accomplish a specific action like transaction use aducidFullOperation() 
- 
-See DemoBank PaymentFragment.java example 
- 
-<code java> 
-aducidFullOperationPost(String url, String methodName,RequestParamsparameters, Handler handler) 
-</code> 
- 
-  * **url**  is address of your **application**  including protocol, e.g. [[https://demobank.aducid.com/demobank|https://demobank.aducid.com/demobank]] 
-  * **methodName**  is path to required page / method (e.g. “/remotePayment”) 
-  * **parameters**  are set of parameters which will be sent to the server, null if there is no parameter 
-  * **handler**  – see above – your callback after ADUCID is done 
-Get the result: 
- 
-<code java> 
-PapiResult result = msg.getData().getParcelable("result"); 
-</code> 
- 
-And parse it – see [[developers:peig-api:android#responses|Responses]] 
- 
  
developers/peig-api/android.1530691106.txt.gz · Last modified: 2018/07/04 07:58 by dskrbek