android-oauth-client icon indicating copy to clipboard operation
android-oauth-client copied to clipboard

DialogFragmentController's getRedirectUri() cannot return custom URL scheme

Open garylai opened this issue 8 years ago • 3 comments

We are implementing OAuth2 flow on android. Our own OAuths system uses custom URL to redirect from authorising page back to the app so that the app can get the authorization_token for exchanging access_token with the OAuth server. Therefore we return our custom url in getRedirectUri() of our AuthorizationUIController.

But It now throws: java.lang.IllegalArgumentException: java.net.MalformedURLException: Unknown protocol: {our custom scheme}

I would like to ask how thie library exchange authorization_token for access_token and if it supports custom URL redirection?

garylai avatar Sep 14 '16 10:09 garylai

Actually, this library uses Web view, so there is no custom uri scheme required. The default http://localhost/Callback is more than enough.

pradeepgudipati avatar Dec 13 '16 02:12 pradeepgudipati

I have the same problem, I need to use a custom scheme as well because the backend will only accept myapp://oauth-callback.

simonzettervall avatar Jan 27 '17 10:01 simonzettervall

I fixed this by this code, which of course is not the best practice but it did get the job done (not sure if any problems will arise because of this, but it surely will):

        /**
	 * Sets up a url stream handler factory. This is necessary as we have a custom scheme/protocol and this in conjunction with our authentication library requires a handler to be declared, even
	 * though this will do nothing.
	 */
	private void setupURLStreamHandlerFactory() {
		URLStreamHandlerFactory urlStreamHandlerFactory = new URLStreamHandlerFactory() {
			@Override
			public URLStreamHandler createURLStreamHandler(String protocol) {
				URLStreamHandler urlStreamHandler;

				if (protocol.equals(mScheme)) {
					urlStreamHandler = new URLStreamHandler() {
						@Override
						protected URLConnection openConnection(URL u) throws IOException {
							return null;
						}
					};
				}

				else {
					urlStreamHandler = null;
				}

				return urlStreamHandler;
			}
		};

		URL.setURLStreamHandlerFactory(urlStreamHandlerFactory);
	}

simonzettervall avatar Jan 31 '17 12:01 simonzettervall