This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
developers:peig-api:android [2018/07/04 08:48] dskrbek [Creating authentication request] |
— (current) | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Developing Android application with ADUCID ====== | ||
- | |||
- | //See [[https:// | ||
- | |||
- | Prerequisites: | ||
- | |||
- | * [[https:// | ||
- | * [[https:// | ||
- | |||
- | 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) | ||
- | </ | ||
- | |||
- | |||
- | - 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) | ||
- | </ | ||
- | |||
- | * **url** | ||
- | * **handler** | ||
- | In your Handler override **handleMessage** | ||
- | |||
- | <code java> | ||
- | com.aducid.peig.lib2.Result result = msg.getData().getParcelable(" | ||
- | </ | ||
- | |||
- | then evaluate it - see [[developers: | ||
- | |||
- | ===== Responses ===== | ||
- | |||
- | Your code should evaluate these possible outcomes: | ||
- | |||
- | I. | ||
- | |||
- | <code java> | ||
- | if result.isOK() | ||
- | </ | ||
- | |||
- | Your session is authenticated | ||
- | |||
- | In DemoBank, result.gerRedirect() contains link to page with account data | ||
- | |||
- | II. | ||
- | |||
- | <code java> | ||
- | else if (result.peigNotInstalled()) | ||
- | </ | ||
- | |||
- | PEIG is not installed. To fix it, you can display a dialog and then open GooglePlay to install it: | ||
- | |||
- | < | ||
- | getPapi().installPEIG(getActivity()); | ||
- | </ | ||
- | |||
- | III. | ||
- | |||
- | <code java> | ||
- | else if (result.isNetworkError()) | ||
- | </ | ||
- | |||
- | 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} | ||
- | </ | ||
- | |||
- | Custom application errors, authentication failed! | ||
- | |||
- | * result.getException() contains ADUCID exception, there are possible states: | ||
- | * result.notAcceptedByUser(): | ||
- | * result.isFactorAbsent(): | ||
- | * 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/ | ||
- | |||
- | < | ||
- | getPapi().getAsyncClient().get(String url, RequestParams parameters, ResponseHandlerInterface responseHandler) | ||
- | </ | ||
- | |||
- | * **url** | ||
- | * **parameters** | ||
- | * **AsyncHttpResponseHandler** | ||
- | ==== 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, | ||
- | </ | ||
- | |||
- | * **url** | ||
- | * **methodName** | ||
- | * **parameters** | ||
- | * **handler** | ||
- | Get the result: | ||
- | |||
- | <code java> | ||
- | PapiResult result = msg.getData().getParcelable(" | ||
- | </ | ||
- | |||
- | And parse it – see [[developers: | ||
- | |||