Unverified Commit a62ab7fe authored by Lucio Maciel's avatar Lucio Maciel Committed by GitHub

Merge pull request #966 from RocketChat/new/login-with-github

[NEW] Login with GitHub (OAuth).
parents e797d903 30eec406
......@@ -55,7 +55,7 @@
android:theme="@style/AppTheme" />
<activity
android:name=".webview.gitlab.ui.GitlabWebViewActivity"
android:name=".webview.oauth.ui.OauthWebViewActivity"
android:windowSoftInputMode="adjustResize|stateAlwaysHidden"
android:theme="@style/AppTheme" />
......
......@@ -115,6 +115,8 @@ class LoginPresenter @Inject constructor(private val view: LoginView,
launchUI(strategy) {
try {
val services = client.settingsOauth().services
val state = "{\"loginStyle\":\"popup\",\"credentialToken\":\"${generateRandomString(40)}\",\"isCordova\":true}".encodeToBase64()
if (services.isNotEmpty()) {
var totalSocialAccountsEnabled = 0
......@@ -125,7 +127,6 @@ class LoginPresenter @Inject constructor(private val view: LoginView,
if (settings.isGithubAuthenticationEnabled()) {
val clientId = getOauthClientId(services, SERVICE_NAME_GITHUB)
if (clientId != null) {
val state = generateRandomString(5)
view.setupGithubButtonListener(UrlHelper.getGithubOauthUrl(clientId, state), state)
view.enableLoginByGithub()
totalSocialAccountsEnabled++
......@@ -150,8 +151,6 @@ class LoginPresenter @Inject constructor(private val view: LoginView,
if (settings.isGitlabAuthenticationEnabled()) {
val clientId = getOauthClientId(services, SERVICE_NAME_GILAB)
if (clientId != null) {
// TODO: Improve this code.
val state = "{\"loginStyle\":\"popup\",\"credentialToken\":\"${generateRandomString(40)}\",\"isCordova\":true}".encodeToBase64()
view.setupGitlabButtonListener(UrlHelper.getGitlabOauthUrl(clientId, currentServer, state), state)
view.enableLoginByGitlab()
totalSocialAccountsEnabled++
......
......@@ -21,9 +21,9 @@ import chat.rocket.android.helper.TextHelper
import chat.rocket.android.util.extensions.*
import chat.rocket.android.webview.cas.ui.INTENT_CAS_TOKEN
import chat.rocket.android.webview.cas.ui.casWebViewIntent
import chat.rocket.android.webview.gitlab.ui.INTENT_OAUTH_CREDENTIAL_SECRET
import chat.rocket.android.webview.gitlab.ui.INTENT_OAUTH_CREDENTIAL_TOKEN
import chat.rocket.android.webview.gitlab.ui.gitlabWebViewIntent
import chat.rocket.android.webview.oauth.ui.INTENT_OAUTH_CREDENTIAL_SECRET
import chat.rocket.android.webview.oauth.ui.INTENT_OAUTH_CREDENTIAL_TOKEN
import chat.rocket.android.webview.oauth.ui.oauthWebViewIntent
import dagger.android.support.AndroidSupportInjection
import kotlinx.android.synthetic.main.fragment_authentication_log_in.*
import javax.inject.Inject
......@@ -210,9 +210,8 @@ class LoginFragment : Fragment(), LoginView {
override fun setupGithubButtonListener(githubUrl: String, state: String) {
button_github.setOnClickListener {
// TODO
// startActivityForResult(context?.githubWebViewIntent(url, state), REQUEST_CODE_FOR_OAUTH)
// activity?.overridePendingTransition(R.anim.slide_up, R.anim.hold)
startActivityForResult(context?.oauthWebViewIntent(githubUrl, state), REQUEST_CODE_FOR_OAUTH)
activity?.overridePendingTransition(R.anim.slide_up, R.anim.hold)
}
}
......@@ -238,7 +237,7 @@ class LoginFragment : Fragment(), LoginView {
override fun setupGitlabButtonListener(gitlabUrl: String, state: String) {
button_gitlab.setOnClickListener {
startActivityForResult(context?.gitlabWebViewIntent(gitlabUrl, state), REQUEST_CODE_FOR_OAUTH)
startActivityForResult(context?.oauthWebViewIntent(gitlabUrl, state), REQUEST_CODE_FOR_OAUTH)
activity?.overridePendingTransition(R.anim.slide_up, R.anim.hold)
}
}
......
package chat.rocket.android.webview.gitlab.ui
package chat.rocket.android.webview.oauth.ui
import android.annotation.SuppressLint
import android.app.Activity
......@@ -16,8 +16,8 @@ import kotlinx.android.synthetic.main.activity_web_view.*
import kotlinx.android.synthetic.main.app_bar.*
import org.json.JSONObject
fun Context.gitlabWebViewIntent(webPageUrl: String, state: String): Intent {
return Intent(this, GitlabWebViewActivity::class.java).apply {
fun Context.oauthWebViewIntent(webPageUrl: String, state: String): Intent {
return Intent(this, OauthWebViewActivity::class.java).apply {
putExtra(INTENT_WEB_PAGE_URL, webPageUrl)
putExtra(INTENT_STATE, state)
}
......@@ -31,7 +31,7 @@ const val INTENT_OAUTH_CREDENTIAL_TOKEN = "credential_token"
const val INTENT_OAUTH_CREDENTIAL_SECRET = "credential_secret"
// Shows a WebView to the user authenticate with your Gitlab credentials.
class GitlabWebViewActivity : AppCompatActivity() {
class OauthWebViewActivity : AppCompatActivity() {
private lateinit var webPageUrl: String
private lateinit var state: String
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment