From b52a0303ca3a6b10661f36a0ff2102eb21dffaf7 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Tue, 1 Sep 2015 06:41:47 +0200 Subject: linked: redesign github resource creation, implement ouath flow (WIP) --- .../keychain/ui/linked/LinkedIdWizard.java | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdWizard.java') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdWizard.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdWizard.java index a29f175c0..2fb6384b2 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdWizard.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdWizard.java @@ -17,7 +17,10 @@ package org.sufficientlysecure.keychain.ui.linked; +import java.util.Random; + import android.content.Context; +import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.support.v4.app.Fragment; @@ -25,6 +28,7 @@ import android.support.v4.app.FragmentTransaction; import android.view.View; import android.view.inputmethod.InputMethodManager; +import org.spongycastle.util.encoders.Hex; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; @@ -32,6 +36,8 @@ import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.ui.base.BaseActivity; +import org.sufficientlysecure.keychain.ui.util.Notify; +import org.sufficientlysecure.keychain.ui.util.Notify.Style; import org.sufficientlysecure.keychain.util.Log; public class LinkedIdWizard extends BaseActivity { @@ -125,4 +131,55 @@ public class LinkedIdWizard extends BaseActivity { inputManager.hideSoftInputFromWindow(v.getWindowToken(), 0); } + private String mOAuthCode, mOAuthState; + + @Override + protected void onNewIntent(Intent intent) { + super.onNewIntent(intent); + + Uri uri = intent.getData(); + if (uri != null) { + Log.d(Constants.TAG, "received oauth uri: " + uri); + String state = uri.getQueryParameter("state"); + if (!mOAuthState.equalsIgnoreCase(state)) { + Notify.create(this, "Authentication Error!", Style.ERROR).show(); + return; + } + mOAuthCode = uri.getQueryParameter("code"); + } else { + Log.d(Constants.TAG, "received oauth uri: null"); + } + + } + + public String oAuthGetCode() { + try { + return mOAuthCode; + } finally { + mOAuthCode = null; + } + } + + public String oAuthGetState() { + return mOAuthState; + } + + public void oAuthRequest(String hostAndPath, String clientId, String scope) { + + byte[] buf = new byte[16]; + new Random().nextBytes(buf); + mOAuthState = new String(Hex.encode(buf)); + + Intent intent = new Intent( + Intent.ACTION_VIEW, + Uri.parse("https://" + hostAndPath + + "?client_id=" + clientId + + "&scope=" + scope + + "&redirect_uri=oauth-openkeychain://linked/" + + "&state=" + mOAuthState)); + + startActivity(intent); + + } + } -- cgit v1.2.3