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
11caf93c
Unverified
Commit
11caf93c
authored
Apr 19, 2018
by
Rafael Kellermann Streit
Committed by
GitHub
Apr 19, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1126 from RocketChat/new/facebook-login
[NEW] Facebook oauth login
parents
b6a83f35
acf53105
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
5 deletions
+42
-5
LoginPresenter.kt
...droid/authentication/login/presentation/LoginPresenter.kt
+7
-4
LoginView.kt
...et/android/authentication/login/presentation/LoginView.kt
+8
-0
LoginFragment.kt
...t/rocket/android/authentication/login/ui/LoginFragment.kt
+9
-0
OauthHelper.kt
app/src/main/java/chat/rocket/android/helper/OauthHelper.kt
+18
-1
No files found.
app/src/main/java/chat/rocket/android/authentication/login/presentation/LoginPresenter.kt
View file @
11caf93c
...
...
@@ -8,7 +8,6 @@ import chat.rocket.android.infrastructure.LocalRepository
import
chat.rocket.android.server.domain.*
import
chat.rocket.android.server.domain.model.Account
import
chat.rocket.android.server.infraestructure.RocketChatClientFactory
import
chat.rocket.android.server.presentation.CheckServerPresenter
import
chat.rocket.android.util.extensions.*
import
chat.rocket.android.util.retryIO
import
chat.rocket.common.RocketChatAuthException
...
...
@@ -31,6 +30,7 @@ private const val SERVICE_NAME_GITHUB = "github"
private
const
val
SERVICE_NAME_GOOGLE
=
"google"
private
const
val
SERVICE_NAME_LINKEDIN
=
"linkedin"
private
const
val
SERVICE_NAME_GILAB
=
"gitlab"
private
const
val
SERVICE_NAME_FACEBOOK
=
"facebook"
class
LoginPresenter
@Inject
constructor
(
private
val
view
:
LoginView
,
...
...
@@ -143,9 +143,12 @@ class LoginPresenter @Inject constructor(
var
totalSocialAccountsEnabled
=
0
if
(
settings
.
isFacebookAuthenticationEnabled
())
{
// //TODO: Remove until we have this implemented
// view.enableLoginByFacebook()
// totalSocialAccountsEnabled++
val
clientId
=
getOauthClientId
(
services
,
SERVICE_NAME_FACEBOOK
)
if
(
clientId
!=
null
)
{
view
.
setupFacebookButtonListener
(
OauthHelper
.
getFacebookOauthUrl
(
clientId
,
currentServer
,
state
),
state
)
view
.
enableLoginByFacebook
()
totalSocialAccountsEnabled
++
}
}
if
(
settings
.
isGithubAuthenticationEnabled
())
{
val
clientId
=
getOauthClientId
(
services
,
SERVICE_NAME_GITHUB
)
...
...
app/src/main/java/chat/rocket/android/authentication/login/presentation/LoginView.kt
View file @
11caf93c
...
...
@@ -145,6 +145,14 @@ interface LoginView : LoadingView, MessageView {
*/
fun
setupLinkedinButtonListener
(
linkedinUrl
:
String
,
state
:
String
)
/**
* Setups the Facebook button when tapped.
*
* @param facebookOauthUrl The Facebook OAuth URL to authenticate with.
* @param state A random string generated by the app, which you'll verify later (to protect against forgery attacks).
*/
fun
setupFacebookButtonListener
(
facebookOauthUrl
:
String
,
state
:
String
)
/**
* Shows the "login by Meteor" view if it is enable by the server settings.
*/
...
...
app/src/main/java/chat/rocket/android/authentication/login/ui/LoginFragment.kt
View file @
11caf93c
...
...
@@ -261,6 +261,15 @@ class LoginFragment : Fragment(), LoginView {
}
}
override
fun
setupFacebookButtonListener
(
facebookOauthUrl
:
String
,
state
:
String
)
{
ui
{
activity
->
button_facebook
.
setOnClickListener
{
startActivityForResult
(
activity
.
oauthWebViewIntent
(
facebookOauthUrl
,
state
),
REQUEST_CODE_FOR_OAUTH
)
activity
.
overridePendingTransition
(
R
.
anim
.
slide_up
,
R
.
anim
.
hold
)
}
}
}
override
fun
enableLoginByGithub
()
{
ui
{
button_github
.
isClickable
=
true
...
...
app/src/main/java/chat/rocket/android/helper/OauthHelper.kt
View file @
11caf93c
...
...
@@ -67,4 +67,21 @@ object OauthHelper {
"&response_type=code"
+
"&scope=read_user"
}
/**
* Returns the Facebook Oauth URL.
*
* @param clientId The Facebook client ID.
* @param serverUrl The server URL.
* @param state An unguessable random string used to protect against forgery attacks.
* @return The Facebook Oauth URL.
*/
fun
getFacebookOauthUrl
(
clientId
:
String
,
serverUrl
:
String
,
state
:
String
):
String
{
return
"https://facebook.com/v2.9/dialog/oauth"
+
"?client_id=$clientId"
+
"&redirect_uri=${serverUrl.removeTrailingSlash()}/_oauth/facebook?close"
+
"&state=$state"
+
"&response_type=code"
+
"&scope=email"
}
}
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