简体   繁体   English

来自Android的AWS Identity TVM注册

[英]AWS Identity TVM registration from android

In Identity TVM registration, Instead of redirecting the user to Identity TVM register.jsp to register, can I directly get username and password of user through my application(Because user must register to use my application) and send them to Identity TVM registration to get registered. 在Identity TVM注册中,可以直接通过我的应用程序获取用户的用户名和密码(因为用户必须注册才能使用我的应用程序),而不是将用户重定向到Identity TVM register.jsp进行注册,而是发送给Identity TVM注册以获取注册。 If yes, how to do it? 如果是,该怎么办?

I had the same problem. 我有同样的问题。 The answer I came up with is to send an HTTP Post request from within your app that replicates what happens on the registration form. 我想到的答案是从您的应用程序内发送HTTP Post请求,该请求复制注册表单上发生的事情。

You will need to create a new layout that captures the username and password (I copied the file login_menu.xml, renamed it register_menu.xml and changed some of the widget ids) 您将需要创建一个捕获用户名和密码的新布局(我复制了文件login_menu.xml,将其重命名为register_menu.xml并更改了一些小部件ID)

In the original Login.java file I changed the onclick action for the Register button to redirect to a new Activity that I called Register.java 在原始的Login.java文件中,我将“注册”按钮的onclick动作更改为重定向到我称为Register.java的新活动。

In Register.java I use the register_menu.xml as the layout file and when a person clicks the register button the following code is run (It gets run from within an AsyncTask): 在Register.java中,我使用register_menu.xml作为布局文件,当人们单击register按钮时,将运行以下代码(它从AsyncTask中运行):

        String registration_url = (PropertyLoader.getInstance().useSSL() ? "https://" : "http://") + PropertyLoader.getInstance().getTokenVendingMachineURL() + "/registeruser";

        URL url = new URL(registration_url);

        Map<String,Object> params = new LinkedHashMap<String,Object>();
        params.put("username", username);
        params.put("password", password);

        StringBuilder postData = new StringBuilder();
        for (Map.Entry<String,Object> param : params.entrySet()) {
            if (postData.length() != 0) postData.append('&');
            postData.append(URLEncoder.encode(param.getKey(), "UTF-8"));
            postData.append('=');
            postData.append(URLEncoder.encode(String.valueOf(param.getValue()), "UTF-8"));
        }
        byte[] postDataBytes = postData.toString().getBytes("UTF-8");


        HttpURLConnection conn = (HttpURLConnection)url.openConnection();
        conn.setReadTimeout(10000 /* milliseconds */);
        conn.setConnectTimeout(15000 /* milliseconds */);
        conn.setDoOutput(true);
        conn.setDoInput(true);
        conn.setInstanceFollowRedirects(false);

        conn.setRequestMethod("POST");
        conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        conn.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
        conn.setUseCaches (false);

        conn.getOutputStream().write(postDataBytes);
        conn.getOutputStream().flush();

        response = conn.getResponseCode();
        Log.d(DEBUG_TAG, "The response is: " + response);
        return response;

I picked up some of the code from other StackOverflow posts about how to generate an HTTP Post using Java ( Java - sending HTTP parameters via POST method easily ) and from the Android Dev site about network connection best practices ( http://developer.android.com/training/basics/network-ops/connecting.html ) 我从其他StackOverflow帖子中获得了一些代码,这些代码与如何使用Java生成HTTP帖子( Java-通过POST方法轻松发送HTTP参数 )以及从Android Dev站点中获取了一些有关网络连接最佳做法的代码( http://developer.android .com / training / basics / network-ops / connecting.html

This should help you get started on your own implementation. 这应该可以帮助您开始自己的实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 凭据在Android上使用AWS TVM过期 - Credentials expired using AWS TVM on Android AWS Identity TVM返回带有``客户端签名不匹配&#39;&#39;错误的Http 401响应 - AWS Identity TVM returns Http 401 response with 'client signature doesnt match' error AWS IOT 在 Android 中即时注册证书 - AWS IOT Just-in-Time Registration of Certificate in Android 在Android中处理AWS User Pool + Fedration Identity令牌刷新系统 - Handling AWS User Pool + Fedration Identity token refresh system in android 将注册数据从Android上传到PHP服务器 - To upload Registration data from Android To PHP server 从Android进行Azure通知中心注册 - Azure Notification Hub Registration from Android 将社交身份联合用户身份验证到AWS Userpool? - Android - Authenticate social identity federation user to AWS Userpool? - Android AWS Identity Token自动售货机-Android代码错误 - AWS Identity Token Vending Machine - Android Code Error Google身份验证因Android上的AWS Cognito身份池而失败 - Google Authentication fails with AWS Cognito Identity Pool on Android Android AWS SDK:在区域元数据中找不到Cognito身份 - Android AWS SDK : Cognito Identity not was not found in region metadata
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM