Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DialogFragmentController's getRedirectUri() cannot return custom URL scheme #63

Open
garylai opened this issue Sep 14, 2016 · 3 comments

Comments

@garylai
Copy link

garylai commented Sep 14, 2016

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?

@pradeepgudipati
Copy link

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

@simonzettervall
Copy link

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

@simonzettervall
Copy link

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);
	}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants