tornados
tornados

Reputation: 86

Gmail OAuth callback issue - We are unable to verify the name associated with this application because it runs on your

I am integrating gmail login and contact list import basically using gmail contacts api v3 (https://developers.google.com/google-apps/contacts/v3/). For calling the API I have to get the user authenticated through OAuth. All works fine but the only issue is that I get a strange message in the web view which opens google screen to ask user to allow access to my app to access his/her contacts. Attached is the screenshot of the issue

Screenshot of issue

The code class I'm using is below

public class GmailDialog extends Dialog {
private ProgressDialog progressDialog1 = null;
ProgressDialog progressdialog;
public static OAuthConsumer consumer;
public static OAuthProvider provider;
String url;
ContainerClass containerClass;
WebView mWebView;
Context context1;

public GmailDialog(Context context, ProgressDialog progressDialog) {
    super(context);
    progressDialog1 = progressDialog;
    context1 = context;
    containerClass = new ContainerClass(context1);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
            .permitAll().build();
    StrictMode.setThreadPolicy(policy);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.ln_dialog);
    setWebView(progressDialog1);
}

@SuppressLint("SetJavaScriptEnabled")
private void setWebView(final ProgressDialog pd) {
    try {

        consumer = new CommonsHttpOAuthConsumer(C.CONSUMER_KEY,
                C.CONSUMER_SECRET);
        provider = new CommonsHttpOAuthProvider(C.REQUEST_URL + "?scope="
                + URLEncoder.encode(C.SCOPE, C.ENCODING)
                + "&xoauth_displayname=" + C.APP_NAME, C.ACCESS_URL,
                C.AUTHORIZE_URL);
        url = provider.retrieveRequestToken(consumer, C.OAUTH_CALLBACK_URL);
    } catch (Exception e) {
        e.printStackTrace();
    }

    mWebView = (WebView) findViewById(R.id.webkitWebView1);
    if (Build.VERSION.SDK_INT >= 11) {
        mWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.loadUrl(url);
    mWebView.getSettings().setRenderPriority(
            WebSettings.RenderPriority.HIGH);
    mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
    mWebView.setWebViewClient(new HelloWebViewClient(pd));
    mWebView.setPictureListener(new PictureListener() {

        @Override
        public void onNewPicture(WebView view, Picture picture) {
            if (progressdialog != null || progressdialog.isShowing()) {
                progressdialog.dismiss();
            }
        }
    });

}

class HelloWebViewClient extends WebViewClient {

    public HelloWebViewClient(ProgressDialog pd) {
        progressdialog = pd;
    }

    @Override
    public void onPageFinished(WebView view, String url) {
        super.onPageFinished(view, url);
    }
    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        super.onPageStarted(view, url, favicon);
        if (!progressdialog.isShowing() || progressdialog == null) {
            if (android.os.Build.VERSION.SDK_INT >= 11) {
                progressdialog = new ProgressDialog(context1,
                        AlertDialog.THEME_HOLO_LIGHT);
            } else {
                progressdialog = new ProgressDialog(context1);
            }
            progressdialog.setMessage("Loading...");
            progressdialog.setIndeterminate(true);
            progressdialog.setCancelable(false);
            progressdialog.show();
        }
    }

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {

        if (url.contains(C.OAUTH_CALLBACK_URL)) {
            Uri uri = Uri.parse(url);

            String verifier = uri.getQueryParameter(OAuth.OAUTH_VERIFIER);
            try {
                provider.retrieveAccessToken(consumer, verifier);
            } catch (Exception e) {
                e.printStackTrace();
            }
            SharedPreferences prefs = PreferenceManager
                    .getDefaultSharedPreferences(context1);
            Editor edit = prefs.edit();
            edit.putString(OAuth.OAUTH_TOKEN, consumer.getToken());
            System.out.println("Token :" + consumer.getToken());
            edit.putString(OAuth.OAUTH_TOKEN_SECRET,
                    consumer.getTokenSecret());
            System.out.println("TokenSecret :" + consumer.getTokenSecret());
            edit.commit();
            cancel();
            for (OnVerifyListener d : listeners) {
                d.onVerify(verifier);
            }
        } else if (url.contains("https://abcd.com/")) {
            cancel();
        } else {

            view.loadUrl(url);
        }

        return true;
    }

}

private List<OnVerifyListener> listeners = new ArrayList<OnVerifyListener>();
public void setVerifierListener(OnVerifyListener data) {
    listeners.add(data);
}
interface OnVerifyListener {
    public void onVerify(String verifier);
}
}

Upvotes: 0

Views: 162

Answers (1)

Erind Shkurti
Erind Shkurti

Reputation: 19

The consent screen is normal for this type of authentication. You might need to re-configure some of the settings in the Google Developer Console for your application so that you don't see the message in yellow.

Upvotes: 1

Related Questions