Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AloqaIM-Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
AloqaIM-Android
Commits
6bc1faf3
Commit
6bc1faf3
authored
Dec 07, 2016
by
Yusuke Iwaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement Facebook authentication. refactor logic for getting "state" parameter.
parent
88174b75
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
67 additions
and
71 deletions
+67
-71
AbstractOAuthFragment.java
.../rocket/android/fragment/oauth/AbstractOAuthFragment.java
+14
-0
FacebookOAuthFragment.java
.../rocket/android/fragment/oauth/FacebookOAuthFragment.java
+26
-0
GitHubOAuthFragment.java
...at/rocket/android/fragment/oauth/GitHubOAuthFragment.java
+10
-26
GoogleOAuthFragment.java
...at/rocket/android/fragment/oauth/GoogleOAuthFragment.java
+12
-28
TwitterOAuthFragment.java
...t/rocket/android/fragment/oauth/TwitterOAuthFragment.java
+2
-16
OAuthProviderInfo.java
.../rocket/android/layouthelper/oauth/OAuthProviderInfo.java
+3
-0
fragment_login.xml
app/src/main/res/layout/fragment_login.xml
+0
-1
No files found.
app/src/main/java/chat/rocket/android/fragment/oauth/AbstractOAuthFragment.java
View file @
6bc1faf3
...
...
@@ -3,6 +3,7 @@ package chat.rocket.android.fragment.oauth;
import
android.os.Bundle
;
import
android.support.annotation.Nullable
;
import
android.text.TextUtils
;
import
android.util.Base64
;
import
android.webkit.JavascriptInterface
;
import
android.webkit.WebView
;
import
chat.rocket.android.api.MethodCallHelper
;
...
...
@@ -11,6 +12,7 @@ import chat.rocket.android.helper.LogcatIfError;
import
chat.rocket.android.model.ServerConfig
;
import
chat.rocket.android.model.ddp.MeteorLoginServiceConfiguration
;
import
chat.rocket.android.realm_helper.RealmStore
;
import
java.nio.charset.Charset
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
timber.log.Timber
;
...
...
@@ -31,6 +33,18 @@ public abstract class AbstractOAuthFragment extends AbstractWebViewFragment {
&&
args
.
containsKey
(
"serverConfigId"
);
}
protected
final
String
getStateString
()
{
try
{
return
Base64
.
encodeToString
(
new
JSONObject
().
put
(
"loginStyle"
,
"popup"
)
.
put
(
"credentialToken"
,
getOAuthServiceName
()
+
System
.
currentTimeMillis
())
.
put
(
"isCordova"
,
true
)
.
toString
()
.
getBytes
(
Charset
.
forName
(
"UTF-8"
)),
Base64
.
NO_WRAP
);
}
catch
(
JSONException
exception
)
{
throw
new
RuntimeException
(
exception
);
}
}
@Override
public
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
Bundle
args
=
getArguments
();
...
...
app/src/main/java/chat/rocket/android/fragment/oauth/FacebookOAuthFragment.java
0 → 100644
View file @
6bc1faf3
package
chat
.
rocket
.
android
.
fragment
.
oauth
;
import
chat.rocket.android.model.ddp.MeteorLoginServiceConfiguration
;
import
okhttp3.HttpUrl
;
public
class
FacebookOAuthFragment
extends
AbstractOAuthFragment
{
@Override
protected
String
getOAuthServiceName
()
{
return
"facebook"
;
}
@Override
protected
String
generateURL
(
MeteorLoginServiceConfiguration
oauthConfig
)
{
return
new
HttpUrl
.
Builder
().
scheme
(
"https"
)
.
host
(
"www.facebook.com"
)
.
addPathSegment
(
"v2.2"
)
.
addPathSegment
(
"dialog"
)
.
addPathSegment
(
"oauth"
)
.
addQueryParameter
(
"client_id"
,
oauthConfig
.
getAppId
())
.
addQueryParameter
(
"redirect_uri"
,
"https://"
+
hostname
+
"/_oauth/facebook?close"
)
.
addQueryParameter
(
"display"
,
"popup"
)
.
addQueryParameter
(
"scope"
,
"email"
)
.
addQueryParameter
(
"state"
,
getStateString
())
.
build
()
.
toString
();
}
}
app/src/main/java/chat/rocket/android/fragment/oauth/GitHubOAuthFragment.java
View file @
6bc1faf3
package
chat
.
rocket
.
android
.
fragment
.
oauth
;
import
android.util.Base64
;
import
chat.rocket.android.model.ddp.MeteorLoginServiceConfiguration
;
import
java.nio.charset.Charset
;
import
okhttp3.HttpUrl
;
import
org.json.JSONObject
;
import
timber.log.Timber
;
public
class
GitHubOAuthFragment
extends
AbstractOAuthFragment
{
...
...
@@ -14,27 +10,15 @@ public class GitHubOAuthFragment extends AbstractOAuthFragment {
}
@Override
protected
String
generateURL
(
MeteorLoginServiceConfiguration
oauthConfig
)
{
final
String
clientId
=
oauthConfig
.
getClientId
();
try
{
String
state
=
Base64
.
encodeToString
(
new
JSONObject
().
put
(
"loginStyle"
,
"popup"
)
.
put
(
"credentialToken"
,
"github"
+
System
.
currentTimeMillis
())
.
put
(
"isCordova"
,
true
)
.
toString
()
.
getBytes
(
Charset
.
forName
(
"UTF-8"
)),
Base64
.
NO_WRAP
);
return
new
HttpUrl
.
Builder
().
scheme
(
"https"
)
.
host
(
"github.com"
)
.
addPathSegment
(
"login"
)
.
addPathSegment
(
"oauth"
)
.
addPathSegment
(
"authorize"
)
.
addQueryParameter
(
"client_id"
,
clientId
)
.
addQueryParameter
(
"client_id"
,
oauthConfig
.
getClientId
()
)
.
addQueryParameter
(
"scope"
,
"user:email"
)
.
addQueryParameter
(
"state"
,
state
)
.
addQueryParameter
(
"state"
,
getStateString
()
)
.
build
()
.
toString
();
}
catch
(
Exception
exception
)
{
Timber
.
e
(
exception
,
"failed to generate GitHub OAUth URL"
);
}
return
null
;
}
}
app/src/main/java/chat/rocket/android/fragment/oauth/GoogleOAuthFragment.java
View file @
6bc1faf3
package
chat
.
rocket
.
android
.
fragment
.
oauth
;
import
android.util.Base64
;
import
chat.rocket.android.model.ddp.MeteorLoginServiceConfiguration
;
import
java.nio.charset.Charset
;
import
okhttp3.HttpUrl
;
import
org.json.JSONObject
;
import
timber.log.Timber
;
public
class
GoogleOAuthFragment
extends
AbstractOAuthFragment
{
...
...
@@ -14,29 +10,17 @@ public class GoogleOAuthFragment extends AbstractOAuthFragment {
}
@Override
protected
String
generateURL
(
MeteorLoginServiceConfiguration
oauthConfig
)
{
final
String
clientId
=
oauthConfig
.
getClientId
();
try
{
String
state
=
Base64
.
encodeToString
(
new
JSONObject
().
put
(
"loginStyle"
,
"popup"
)
.
put
(
"credentialToken"
,
"google"
+
System
.
currentTimeMillis
())
.
put
(
"isCordova"
,
true
)
.
toString
()
.
getBytes
(
Charset
.
forName
(
"UTF-8"
)),
Base64
.
NO_WRAP
);
return
new
HttpUrl
.
Builder
().
scheme
(
"https"
)
.
host
(
"accounts.google.com"
)
.
addPathSegment
(
"o"
)
.
addPathSegment
(
"oauth2"
)
.
addPathSegment
(
"auth"
)
.
addQueryParameter
(
"response_type"
,
"code"
)
.
addQueryParameter
(
"client_id"
,
clientId
)
.
addQueryParameter
(
"client_id"
,
oauthConfig
.
getClientId
()
)
.
addQueryParameter
(
"scope"
,
"profile email"
)
.
addQueryParameter
(
"redirect_uri"
,
"https://"
+
hostname
+
"/_oauth/google?close"
)
.
addQueryParameter
(
"state"
,
state
)
.
addQueryParameter
(
"state"
,
getStateString
()
)
.
build
()
.
toString
();
}
catch
(
Exception
exception
)
{
Timber
.
e
(
exception
,
"failed to generate Google OAUth URL"
);
}
return
null
;
}
}
app/src/main/java/chat/rocket/android/fragment/oauth/TwitterOAuthFragment.java
View file @
6bc1faf3
package
chat
.
rocket
.
android
.
fragment
.
oauth
;
import
android.util.Base64
;
import
chat.rocket.android.model.ddp.MeteorLoginServiceConfiguration
;
import
java.nio.charset.Charset
;
import
org.json.JSONObject
;
import
timber.log.Timber
;
public
class
TwitterOAuthFragment
extends
AbstractOAuthFragment
{
...
...
@@ -13,17 +9,7 @@ public class TwitterOAuthFragment extends AbstractOAuthFragment {
}
@Override
protected
String
generateURL
(
MeteorLoginServiceConfiguration
oauthConfig
)
{
try
{
String
state
=
Base64
.
encodeToString
(
new
JSONObject
().
put
(
"loginStyle"
,
"popup"
)
.
put
(
"credentialToken"
,
"twitter"
+
System
.
currentTimeMillis
())
.
put
(
"isCordova"
,
true
)
.
toString
()
.
getBytes
(
Charset
.
forName
(
"UTF-8"
)),
Base64
.
NO_WRAP
);
return
"https://"
+
hostname
+
"/_oauth/twitter/?requestTokenAndRedirect=true&state="
+
state
;
}
catch
(
Exception
exception
)
{
Timber
.
e
(
exception
,
"failed to generate Twitter OAUth URL"
);
}
return
null
;
return
"https://"
+
hostname
+
"/_oauth/twitter/"
+
"?requestTokenAndRedirect=true&state="
+
getStateString
();
}
}
app/src/main/java/chat/rocket/android/layouthelper/oauth/OAuthProviderInfo.java
View file @
6bc1faf3
...
...
@@ -2,6 +2,7 @@ package chat.rocket.android.layouthelper.oauth;
import
chat.rocket.android.R
;
import
chat.rocket.android.fragment.oauth.AbstractOAuthFragment
;
import
chat.rocket.android.fragment.oauth.FacebookOAuthFragment
;
import
chat.rocket.android.fragment.oauth.GitHubOAuthFragment
;
import
chat.rocket.android.fragment.oauth.GoogleOAuthFragment
;
import
chat.rocket.android.fragment.oauth.TwitterOAuthFragment
;
...
...
@@ -27,6 +28,8 @@ public class OAuthProviderInfo {
"github"
,
R
.
id
.
btn_login_with_github
,
GitHubOAuthFragment
.
class
));
add
(
new
OAuthProviderInfo
(
"google"
,
R
.
id
.
btn_login_with_google
,
GoogleOAuthFragment
.
class
));
add
(
new
OAuthProviderInfo
(
"facebook"
,
R
.
id
.
btn_login_with_facebook
,
FacebookOAuthFragment
.
class
));
}
};
}
app/src/main/res/layout/fragment_login.xml
View file @
6bc1faf3
...
...
@@ -31,7 +31,6 @@
android:id=
"@+id/btn_login_with_facebook"
android:layout_width=
"48dp"
android:layout_height=
"48dp"
android:enabled=
"false"
android:layout_marginEnd=
"@dimen/margin_8"
android:text=
"@string/fa_facebook_official"
android:textSize=
"16dp"
/>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment