0

I am using this post and answer to try and retrieve the authorization code from my redirect url but it is not working yet the guy has accepted it as a correct answer:

How to get Authorization code using Intent

Here is the code that I have used:

public class Kiteworks_SignIn extends Activity {

Uri uri;
String redirect_uri;
String authcode;
WebView webView;
Button browser;
Intent browserIntent;
String kiteworksurl;
Intent getAuthCode;



@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.kiteworks_sign_in);

    browser = findViewById(R.id.buttonBrowser);

    browser.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            getAuthCode = new Intent(Intent.ACTION_VIEW, Uri.parse("https://sync.almacgroup.com/oauth/authorize?client_id=1fb7c350-bb6a-5741-86b9-43afc2f1642f&redirect_uri=https://sync.almacgroup.com/rest/callback.html?display%3Dmobile&response_type=code&scope=&m=1&force_login=1"));
            startActivity(getAuthCode);

        }
    });
}

@Override
protected void onNewIntent(Intent intent) {
    Uri uri = getAuthCode.getData();
    if (uri != null) {
        String mainPart = uri.toString().split("#")[1];
        String[] arguments = mainPart.split("&");
        String argument = arguments[0];
        String token = argument.split("=")[1];
        Toast.makeText(this, token, Toast.LENGTH_SHORT).show();
    }
}

Basically I have the exact same scenario as this guy. My app redirects and I am unsure as to how to extract the authorization code. I have debugged the OnNewIntent method and it is not catching or hitting the debug so I cant see if there is any problems.

Here is the format of my redirect Url after it has been reached:

https://sync.almacgroup.com/rest/callback.html?display=mobile&code=(THEN THE CODE FOLLOWS)

Am I doing something different or why is this not working?

Thanks

Aaron
  • 47
  • 11

1 Answers1

0

If you need to split the code from this kind of url why the hell you split from "#". You can use this.

    String mainPart = uri.toString();
    String[] data = mainPart.split("?");
    String arguments = data[1];
    String[] argument = arguments.split("=");
    String token = argument[1];
    Toast.makeText(this, token, Toast.LENGTH_SHORT).show();