Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Oauth+;PHP(Symfony3+;FOS Oauth服务器包)_Android_Oauth_Symfony_Fosoauthserverbundle - Fatal编程技术网

Android Oauth+;PHP(Symfony3+;FOS Oauth服务器包)

Android Oauth+;PHP(Symfony3+;FOS Oauth服务器包),android,oauth,symfony,fosoauthserverbundle,Android,Oauth,Symfony,Fosoauthserverbundle,我正试图在我的Android(基于KitKat)应用程序中实现oauth授权 我已经准备了自己的基于php的oauth2服务器(Symfony3框架+FOS Oauth服务器包)。 现在我需要在android应用程序中进行授权。 我想知道在互联网上,我没有找到任何解决方案,可以帮助我做授权。有很多文档使用google或其他社会服务描述OAUTH,但正如我所说的,我有自己的OAUTH服务器 我试图在移动应用程序中制作一些东西,但遇到了一些问题。 Oauth流需要在应用程序中打开web视图元素,并接

我正试图在我的Android(基于KitKat)应用程序中实现oauth授权

我已经准备了自己的基于php的oauth2服务器(Symfony3框架+FOS Oauth服务器包)。 现在我需要在android应用程序中进行授权。 我想知道在互联网上,我没有找到任何解决方案,可以帮助我做授权。有很多文档使用google或其他社会服务描述OAUTH,但正如我所说的,我有自己的OAUTH服务器

我试图在移动应用程序中制作一些东西,但遇到了一些问题。 Oauth流需要在应用程序中打开web视图元素,并接受我的应用程序使用我的web帐户。这个流程在我的服务器上运行,但我不知道如何在应用程序中实现。我试图打开web视图,我正在传递身份验证流并获取代码,但它显示在webview中。 我找到了一个方法,它捕捉web视图加载的时刻,在本例中,我可以从web视图URL捕捉一些参数,但我的web中的oauth流是在防火墙下的。若我并没有在web中获得授权,flow会将我重定向到登录页面,稍后,在成功登录后,它会为我提供接受或拒绝使用我的帐户数据的服务。所以,我不能使用onPageFinished或其他东西

其他情况下,我可以通过传递登录名、密码、客户端id、密码和其他参数来获得访问令牌。我想在应用程序中提供两个服务,第一个将在本地检查-如果我的令牌没有过期,如果过期-它将运行第二个服务-刷新我的令牌-向我的oauth服务器(web应用程序)发出http请求。但我在这里遇到了另一个问题

我正在使用Volley库进行http调用。据我所知,volley运行对web的异步请求。我试图将我的请求转移到单独的类/服务中。 但我在可空上下文方面遇到了问题。好啊我决定在activity类中发出请求(虽然不是很好的用法,但还行),在那里,我遇到了另一个问题。 我已经定义了按钮,并为其单击了侦听器。 我想在用户将登录名和密码路径输入EditText字段和onClick for sign-in按钮后对其进行身份验证-我正在检查SharedReferences的客户端id,如果为空-我想从web获取新的oauth客户端id,我正在onClick Listener中运行新的截取请求。问题是-我无法正确获得响应。 我的代码示例

``` signIn.setOnClickListener(新的OnClickListener(){

@覆盖
公共void onClick(视图){
字符串login=LoginView.getText().toString();
字符串密码=PasswordView.getText().toString();
auth_dialog=新建对话框(LoginActivity.this);
auth_dialog.setContentView(R.layout.auth_dialog);
preferences=PreferenceManager.GetDefaultSharedReferences(getApplicationContext());
preferences.edit().putString(getString(R.string.oauth_client_id),null.apply();
String clientId=preferences.getString(getString(R.String.oauth\u client\u id),null);
preferences.edit().putString(getString(R.string.user_login),login.apply();
preferences.edit().putString(getString(R.string.user_password)、password.apply();
if(clientId==null){
RequestQueue=Volley.newRequestQueue(上下文);
SharedReferences首选项=PreferenceManager.GetDefaultSharedReferences(上下文);
stringurl=context.getString(R.String.url)+context.getString(R.String.url_标记)+“?”;
url++=“client_id=“+preferences.getString(context.getString(R.string.oauth_client_id)),null)+“&”;
url++=“client_secret=“+preferences.getString(context.getString(R.string.oauth_client_secret))null)+“&”;
url++=“授权类型=“+context.getString(R.string.grant类型密码)+”&”;
url++=“username=”+preferences.getString(context.getString(R.string.user\u login),null)+“&”;
url+=“password=“+preferences.getString(context.getString(R.string.user\u password)),null;
StringRequest StringRequest=新建StringRequest(Request.Method.GET,url,new Response.Listener()){
@凌驾
公共void onResponse(字符串响应){
clientResponse=响应;
}
},new Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
Toast.makeText(上下文,“获取令牌的请求失败”,Toast.LENGTH_SHORT.show();
}
});
添加(stringRequest);
}
Log.d(“VIOO_APP”,clientResponse);//这是发生错误的地方
token=getToken();
Toast.makeText(getApplicationContext(),token.getAccessToken(),Toast.LENGTH_LONG.show();
}
});```
我想说的是,所有变量都已定义——它是来自ButtonOnClick Listener的jsut部分代码<代码>客户端响应变量在活动类中定义为全局变量

当然,我可以把我的逻辑放在响应语句中——当截击得到响应时——做我的事情,但我认为——稍后,我的代码将无法阅读,这不是构建应用程序结构的好方法。为了回应另一个请求而提出请求完全是胡说八道,诸如此类

当我的要求在另一个班工作时,我有很好的案例。 我在互联网上看到过一些例子——一些人是如何尝试使用应用服务的——通过截击发出请求的,但这些信息现在可能并不真实。我发现的每一个网络案例都不会起作用,也不会提供无用的信息

我认为这项挑战是不可能获胜的。我尝试过的所有东西——都失败了,不会起作用。
我希望,我充分解释了我的问题。 多谢各位

        @Override
        public void onClick(View view) {
            String login = LoginView.getText().toString();
            String password = PasswordView.getText().toString();

            auth_dialog = new Dialog(LoginActivity.this);
            auth_dialog.setContentView(R.layout.auth_dialog);
            preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
            preferences.edit().putString(getString(R.string.oauth_client_id), null).apply();
            String clientId = preferences.getString(getString(R.string.oauth_client_id), null);
            preferences.edit().putString(getString(R.string.user_login), login).apply();
            preferences.edit().putString(getString(R.string.user_password), password).apply();

            if(clientId == null){
                RequestQueue queue = Volley.newRequestQueue(context);
                SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
                String url = context.getString(R.string.url) + context.getString(R.string.url_token) + "?";
                url += "client_id=" + preferences.getString(context.getString(R.string.oauth_client_id), null) + "&";
                url += "client_secret=" + preferences.getString(context.getString(R.string.oauth_client_secret), null) + "&";
                url += "grant_type=" + context.getString(R.string.grant_type_password) + "&";
                url += "username=" + preferences.getString(context.getString(R.string.user_login), null) + "&";
                url += "password=" + preferences.getString(context.getString(R.string.user_password), null);

                StringRequest stringRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response){
                        clientResponse = response;
                    }
                }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Toast.makeText(context, "Request for getting Token failed", Toast.LENGTH_SHORT).show();
                    }
                });
                queue.add(stringRequest);
            }
            Log.d("VIOO_APP", clientResponse);// THIS IS THE PLACE WHERE ERROR HAPPENS
            token = getToken();
            Toast.makeText(getApplicationContext(), token.getAccessToken(), Toast.LENGTH_LONG).show();
        }
    });```