Skip to content

Commit

Permalink
Add publish scripts (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
Miguel Villaseñor committed Jun 1, 2020
1 parent 1f82f3f commit 3181d61
Show file tree
Hide file tree
Showing 14 changed files with 179 additions and 34 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/publish-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Publish library

on:
release:
types:
- created

jobs:
publish-library:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Publish to bintray
env:
BINTRAY_USER: ${{ secrets.BINTRAY_USER}}
BINTRAY_API_KEY: ${{ secrets.BINTRAY_API_KEY}}
run: ./gradlew install bintrayUpload
3 changes: 1 addition & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,11 @@ android {
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(":oneloginoidc")

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.core:core-ktx:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.navigation:navigation-fragment-ktx:2.2.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.2.2'
Expand Down
1 change: 0 additions & 1 deletion appjava/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ android {
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(":oneloginoidc")

implementation 'androidx.appcompat:appcompat:1.1.0'
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ buildscript {
repositories {
google()
jcenter()

}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
Expand All @@ -15,14 +14,15 @@ buildscript {
classpath "org.jetbrains.dokka:dokka-gradle-plugin:${dokka_version}"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
}
}

allprojects {
repositories {
google()
jcenter()

}
}

Expand Down
45 changes: 45 additions & 0 deletions oneloginoidc/bintray.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
apply plugin: 'com.jfrog.bintray'

version = '1.0.0'

task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
archiveClassifier.set('sources')
}

task javadoc(type: Javadoc, dependsOn: dokka) {
}

task javadocJar(type: Jar, dependsOn: javadoc) {
archiveClassifier.set('javadoc')
from javadoc.destinationDir
}

artifacts {
archives javadocJar
archives sourcesJar
}

Properties properties = new Properties()
def propertiesFile = project.rootProject.file('local.properties')
if (propertiesFile.exists()) {
properties.load(propertiesFile.newDataInputStream())
}

// Bintray
bintray {
user = properties.getProperty("bintray.user") ?: System.getenv('BINTRAY_USER')
key = properties.getProperty("bintray.apikey") ?: System.getenv('BINTRAY_API_KEY')

pkg {
repo = 'maven'
name = 'com.onelogin.oidc'
configurations = ['archives']
desc = 'OneLogin Android OIDC SDK.'
websiteUrl = 'https://github.com/onelogin/onelogin-oidc-android'
vcsUrl = 'https://github.com/onelogin/onelogin-oidc-android.git'
licenses = ["MIT"]
publish = true
publicDownloadNumbers = true
}
}
12 changes: 7 additions & 5 deletions oneloginoidc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,14 @@ dokka {
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.core:core-ktx:1.3.0'
implementation 'net.openid:appauth:0.7.1'
implementation 'com.squareup.okhttp3:okhttp:3.12.0'
implementation 'com.squareup.okhttp3:okhttp:4.5.0'
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.3'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.7'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.7'
implementation 'com.jakewharton.timber:timber:4.7.1'

testImplementation 'junit:junit:4.12'
Expand All @@ -51,3 +50,6 @@ dependencies {
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

apply from: 'install.gradle'
apply from: 'bintray.gradle'
50 changes: 50 additions & 0 deletions oneloginoidc/install.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
apply plugin: 'com.github.dcendents.android-maven'

group = 'com.onelogin.oidc'

install {
repositories.mavenInstaller {
pom {
project {
packaging 'aar'
groupId 'com.onelogin.oidc'
artifactId 'oidc'
name 'OneLogin OIDC SDK'
description 'OneLogin OIDC SDK for android.'
url 'https://github.com/onelogin/onelogin-oidc-android'

licenses {
license {
name 'The MIT License'
url 'https://opensource.org/licenses/MIT'
}
}

developers {
developer {
id 'miguelvillasenor'
name 'Miguel Villaseñor'
email 'miguel.villasenor@onelogin.com'
}
}

scm {
connection 'https://github.com/onelogin/onelogin-oidc-android.git'
developerConnection 'https://github.com/onelogin/onelogin-oidc-android.git'
url 'https://github.com/onelogin/onelogin-oidc-android'
}
}
withXml {
def dependenciesNode = asNode().appendNode('dependencies')

//Iterate over the compile dependencies (we don't want the test ones), adding a <dependency> node for each
configurations.implementation.allDependencies.each {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
}
}
}
}
}
18 changes: 13 additions & 5 deletions oneloginoidc/src/main/java/com/onelogin/oidc/OIDCClientFactory.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package com.onelogin.oidc

import android.content.Context
import android.os.Bundle
import com.onelogin.oidc.data.AuthorizationServiceProvider
import com.onelogin.oidc.data.OKHttpProvider
import com.onelogin.oidc.data.network.ConfigurationClient
import com.onelogin.oidc.data.network.NetworkClient
import com.onelogin.oidc.data.repository.OIDCRepositoryImpl
import com.onelogin.oidc.data.stores.OneLoginEncryptionManager
import com.onelogin.oidc.data.stores.OneLoginEncryptionManager.Companion.ONELOGIN_SHARED_PREFERENCES
import com.onelogin.oidc.data.stores.OneLoginStore
import com.onelogin.oidc.login.SignInFragment
import com.onelogin.oidc.login.SignInFragment.Companion.ARG_AUTHORIZATION_REQUEST
import com.onelogin.oidc.login.SignInManagerImpl
import net.openid.appauth.AuthorizationService

internal class OIDCClientFactory(
private val context: Context,
Expand All @@ -22,17 +25,22 @@ internal class OIDCClientFactory(
val encryptionManager =
configuration.encryptionManager ?: OneLoginEncryptionManager(context)
val networkClient = NetworkClient(okHttpClient, configuration)
val preferences = context.getSharedPreferences("oneloginPreferences", Context.MODE_PRIVATE)
val preferences = context.getSharedPreferences(ONELOGIN_SHARED_PREFERENCES, Context.MODE_PRIVATE)
val store = OneLoginStore(preferences)
val repository =
OIDCRepositoryImpl(configuration, configurationClient, store, encryptionManager)
val authorizationService = AuthorizationService(context)
AuthorizationServiceProvider.init(context)
val authorizationService = AuthorizationServiceProvider.authorizationService
val signInManager = SignInManagerImpl(
configuration,
authorizationService,
repository
) { service, authorizationRequest ->
SignInFragment(service, authorizationRequest)
) { authorizationRequest ->
val fragment = SignInFragment()
val args = Bundle()
args.putString(ARG_AUTHORIZATION_REQUEST, authorizationRequest.jsonSerializeString())
fragment.arguments = args
fragment
}

return OIDCClientImpl(authorizationService, networkClient, repository, signInManager)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.onelogin.oidc.data

import android.content.Context
import net.openid.appauth.AuthorizationService

object AuthorizationServiceProvider {

val authorizationService by lazy {
AuthorizationService(context)
}

private lateinit var context: Context

fun init(context: Context) {
this.context = context
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal class NetworkClient(
if (response.isSuccessful) {
return@withContext
}
response.body()?.let {
response.body?.let {
val error = Gson().fromJson(it.string(), ErrorResponse::class.java)
throw NetworkException(error.errorDescription)
} ?: throw NetworkException("Unable to revoke token")
Expand All @@ -51,10 +51,10 @@ internal class NetworkClient(
val response = okHttpClient.newCall(request).execute()

return@withContext response.use {
if (response.isSuccessful && response.body() != null) {
Gson().fromJson(response.body()!!.string(), UserInfo::class.java)
if (response.isSuccessful && response.body != null) {
Gson().fromJson(response.body!!.string(), UserInfo::class.java)
} else {
response.body()?.let {
response.body?.let {
val error = Gson().fromJson(it.string(), ErrorResponse::class.java)
throw NetworkException(error.errorDescription)
} ?: throw NetworkException("Unable to get user info")
Expand All @@ -77,10 +77,10 @@ internal class NetworkClient(
val response = okHttpClient.newCall(request).execute()

return@withContext response.use {
if (response.isSuccessful && response.body() != null) {
Gson().fromJson(response.body()!!.string(), TokenIntrospection::class.java)
if (response.isSuccessful && response.body != null) {
Gson().fromJson(response.body!!.string(), TokenIntrospection::class.java)
} else {
response.body()?.let {
response.body?.let {
val error = Gson().fromJson(it.string(), ErrorResponse::class.java)
throw NetworkException(error.errorDescription)
} ?: throw NetworkException("Unable to introspect token")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ class OneLoginEncryptionManager(
try {
sharedPreferences = context.getSharedPreferences(ONELOGIN_SHARED_PREFERENCES, MODE_PRIVATE)
if (!containsAlias()) {
sharedPreferences.edit().clear().apply()
generateKeys()
} else {
if (!verifyKeys()) {
removeKeys()
sharedPreferences.edit().clear().apply()
generateKeys()
}
}
Expand Down Expand Up @@ -258,6 +260,6 @@ class OneLoginEncryptionManager(
private const val RSA_ENCRYPTION = "RSA"
private const val RSA_MODE = "RSA/ECB/PKCS1Padding"
private const val AES_ENCRYPTED_KEY = "oneloginAesEncrypted"
private const val ONELOGIN_SHARED_PREFERENCES = "oneloginPreferences"
internal const val ONELOGIN_SHARED_PREFERENCES = "oneloginPreferences"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@ package com.onelogin.oidc.login

import android.content.Intent
import androidx.fragment.app.Fragment
import com.onelogin.oidc.data.AuthorizationServiceProvider
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.channels.ClosedSendChannelException
import net.openid.appauth.AuthorizationException
import net.openid.appauth.AuthorizationRequest
import net.openid.appauth.AuthorizationResponse
import net.openid.appauth.AuthorizationService
import timber.log.Timber


internal class SignInFragment(
private val authorizationService: AuthorizationService,
private var authorizationRequest: AuthorizationRequest?
) : Fragment() {
internal class SignInFragment : Fragment() {

internal val resultChannel = Channel<Pair<AuthorizationResponse?, AuthorizationException?>>()

override fun onResume() {
super.onResume()
val authorizationRequestString = arguments?.getString(ARG_AUTHORIZATION_REQUEST)
val authorizationRequest = authorizationRequestString?.let { AuthorizationRequest.jsonDeserialize(authorizationRequestString) }
authorizationRequest?.let {
val authIntent = authorizationService.getAuthorizationRequestIntent(it)

val authIntent = AuthorizationServiceProvider.authorizationService.getAuthorizationRequestIntent(it)
startActivityForResult(authIntent, AUTHORIZATION_REQUEST_CODE)
authorizationRequest = null
arguments?.putString(ARG_AUTHORIZATION_REQUEST, null)
}
}

Expand All @@ -50,6 +50,7 @@ internal class SignInFragment(

companion object {
internal const val AUTHORIZATION_REQUEST_CODE = 34001
internal const val ARG_AUTHORIZATION_REQUEST = "authorization_request"
internal const val LOGIN_FRAGMENT_TAG = "login_fragment"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal class SignInManagerImpl(
private val configuration: OIDCConfiguration,
private val authorizationService: AuthorizationService,
private val repository: OIDCRepository,
private val signInFragmentProvider: (AuthorizationService, AuthorizationRequest) -> SignInFragment
private val signInFragmentProvider: (AuthorizationRequest) -> SignInFragment
) : SignInManager {

override suspend fun signIn(
Expand All @@ -26,7 +26,7 @@ internal class SignInManagerImpl(

if (activity is FragmentActivity) {
removeFragmentIfAttached(activity)
val loginFragment = signInFragmentProvider(authorizationService, authorizationRequest)
val loginFragment = signInFragmentProvider(authorizationRequest)
attachLoginFragment(activity, loginFragment)
loginFragment.resultChannel.consumeEach { (response, exception) ->
if (exception != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ class SignInManagerTest {
.clientId("testClientId")
.build()

lateinit var signInManager: SignInManager
private lateinit var signInManager: SignInManager

@Before
fun setup() {
signInManager =
SignInManagerImpl(oidcConfiguration, authorizationService, repository) { _, _ ->
SignInManagerImpl(oidcConfiguration, authorizationService, repository) { _ ->
signInFragment
}

Expand Down

0 comments on commit 3181d61

Please sign in to comment.