How to use redirect URI with OAuth2.0 and Box for my Android application?

6.4k views Asked by At

I have an Android application that makes use of the Box sdk. The Box functionality has been broken for a while as I'm finally getting around to updating to the most recent version of the sdk. When I try to authenticate a user from my application using the OAuthActivity I'm informed that "error: redirect_uri_missing".

When I view my application on the Box developers page, I see that it expects me to enter a redirect uri in the OAuth2 Parameters section. But, despite searching for an answer, I'm thoroughly confused as to what to enter here?

EDIT:

Based on the below API, it would seem that I could use the below method to authenticate to box without a redirect uri set. However, when I use it as follows, I get: "Errror: insecure_redirect_uri".

OAuthActivity.createOAuthActivityIntent(activity, KEY, SECRET, false, "http://localhost");

/**
     * Create intent to launch OAuthActivity. Notes about redirect url parameter: If you already set redirect url in <a
     * href="https://cloud.app.box.com/developers/services">box dev console</a>, you should pass in the same redirect url or use null for redirect url. If you
     * didn't set it in box dev console, you should pass in a url. In case you don't have a redirect server you can simply use "http://localhost".
     * 
     * @param context
     *            context
     * @param clientId
     *            your box client id
     * @param clientSecret
     *            your box client secret
     * @param allowShowRedirectPage
     *            Whether you want to load/show redirected page after OAuth flow is done.
     * @param redirectUrl
     *            redirect url, if you already set redirect url in <a href="https://cloud.app.box.com/developers/services">box dev console</a>, leave this null
     *            or use the same url, otherwise this field is required. You can use "http://localhost" if you don't have a redirect server.
     * @return
     */
    public static Intent createOAuthActivityIntent(final Context context, final String clientId, final String clientSecret,
        final boolean allowShowRedirectPage, String redirectUrl)
2

There are 2 answers

0
Murtaza Khursheed Hussain On

You can enter http://127.0.0.1 or https://127.0.0.1 (loopback address)

0
Greg On

Sorry for the confusion, some of this documentation is out of date. You should use https://localhost as the redirect URI on your application configuration page (which can be found here). We no longer allow insecure redirect URIs, meaning that they must use HTTPS. Once the redirect URI is set for you app, you can leave the redirectUrl parameter null.