Skip to content

Commit

Permalink
Add LoginActivity and OAuth-related files and settings
Browse files Browse the repository at this point in the history
  • Loading branch information
jageishi committed Dec 4, 2019
1 parent ee2267f commit 5d547e2
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 0 deletions.
16 changes: 16 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,20 @@ android {
versionName "0.9.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())

debug {
buildConfigField("String", "CONSUMER_KEY", properties.getProperty("CONSUMER_KEY_DEBUG"))
buildConfigField("String", "CONSUMER_SECRET", properties.getProperty("CONSUMER_SECRET_DEBUG"))
}

release {
buildConfigField("String", "CONSUMER_KEY", properties.getProperty("CONSUMER_KEY"))
buildConfigField("String", "CONSUMER_SECRET", properties.getProperty("CONSUMER_SECRET"))
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
Expand Down Expand Up @@ -56,6 +68,10 @@ dependencies {
implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofit_version"
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"

def scribe_java_version = '6.9.0'
implementation "com.github.scribejava:scribejava:$scribe_java_version"
implementation "com.github.scribejava:scribejava-core:$scribe_java_version"

implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.1.0'
testImplementation 'junit:junit:4.12'
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
<activity
android:name=".search.SearchResultActivity"
android:theme="@style/AppTheme.ActionBar" />
<activity
android:name=".login.LoginActivity"
android:theme="@style/AppTheme.ActionBar" />
<activity
android:name="com.google.android.gms.oss.licenses.OssLicensesMenuActivity"
android:theme="@style/AppTheme.ActionBar" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.ageage.eggplant.common.oauth

import com.github.scribejava.core.builder.api.DefaultApi10a

class HatenaOAuthApi : DefaultApi10a() {
override fun getRequestTokenEndpoint(): String {
return "https://www.hatena.com/oauth/initiate?scope=read_public,write_public"
}

override fun getAuthorizationBaseUrl(): String {
return "https://www.hatena.ne.jp/touch/oauth/authorize"
}

override fun getAccessTokenEndpoint(): String {
return "https://www.hatena.com/oauth/token"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.ageage.eggplant.common.oauth

import com.github.scribejava.core.builder.ServiceBuilder
import com.github.scribejava.core.model.OAuth1RequestToken
import com.github.scribejava.core.oauth.OAuth10aService
import io.reactivex.Single

private const val CALLBACK = "https://ageage.org"

class HatenaOAuthManager(
private val consumerKey: String,
private val consumerSecret: String
) {

private var service: OAuth10aService? = null
private var requestToken: OAuth1RequestToken? = null

fun fetchAuthorizationUrl(): Single<String?> {
return Single.create {
service = ServiceBuilder(consumerKey)
.apiSecret(consumerSecret)
.callback(CALLBACK)
.build(HatenaOAuthApi())

requestToken = service?.requestToken
service?.getAuthorizationUrl(requestToken)?.let { token ->
it.onSuccess(token)
}
}
}

fun fetchAccessToken(oauthVerifier: String): Single<String> {
return Single.create {
service?.let { oAuthService ->
val accessToken =
oAuthService.getAccessToken(requestToken, oauthVerifier)
it.onSuccess(accessToken.rawResponse)
}
}
}

}
13 changes: 13 additions & 0 deletions app/src/main/java/org/ageage/eggplant/login/LoginActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.ageage.eggplant.login

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import org.ageage.eggplant.R

class LoginActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login)
}
}
8 changes: 8 additions & 0 deletions app/src/main/res/layout/activity_login.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".login.LoginActivity">

</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit 5d547e2

Please sign in to comment.