Skip to content

Commit

Permalink
Merge pull request #10 from googlecodelabs/yaraki-cookie
Browse files Browse the repository at this point in the history
Update to the latest server API
  • Loading branch information
agektmr authored Nov 17, 2020
2 parents 9149851 + 311869f commit ac04b3e
Show file tree
Hide file tree
Showing 30 changed files with 508 additions and 539 deletions.
6 changes: 6 additions & 0 deletions android/.idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions android/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion android/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions android/app-start/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ dependencies {
implementation 'androidx.fragment:fragment-ktx:1.2.5'

implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'

def lifecycle_version = '2.2.0'
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
Expand All @@ -89,7 +89,7 @@ dependencies {
implementation "com.squareup.okhttp3:okhttp:$okhttp_version"
implementation "com.squareup.okhttp3:logging-interceptor:$okhttp_version"

testImplementation 'junit:junit:4.13'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test:runner:1.3.0'
androidTestImplementation 'androidx.test:rules:1.3.0'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,20 @@

package com.example.android.fido2

import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.widget.Toast
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.fragment.app.commit
import androidx.lifecycle.observe
import com.example.android.fido2.repository.SignInState
import com.example.android.fido2.ui.auth.AuthFragment
import com.example.android.fido2.ui.home.HomeFragment
import com.example.android.fido2.ui.username.UsernameFragment
import com.google.android.gms.fido.Fido
import com.google.android.gms.fido.fido2.api.common.AuthenticatorErrorResponse

class MainActivity : AppCompatActivity() {

companion object {
private const val TAG = "MainActivity"
const val REQUEST_FIDO2_REGISTER = 1
const val REQUEST_FIDO2_SIGNIN = 2
}

private val viewModel: MainViewModel by viewModels()

override fun onCreate(savedInstanceState: Bundle?) {
Expand Down Expand Up @@ -67,46 +57,6 @@ class MainActivity : AppCompatActivity() {
}
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
when (requestCode) {
REQUEST_FIDO2_REGISTER -> {
val errorExtra = data?.getByteArrayExtra(Fido.FIDO2_KEY_ERROR_EXTRA)
if (errorExtra != null) {
val error = AuthenticatorErrorResponse.deserializeFromBytes(errorExtra)
error.errorMessage?.let { errorMessage ->
Toast.makeText(this, errorMessage, Toast.LENGTH_LONG).show()
Log.e(TAG, errorMessage)
}
} else if (resultCode != RESULT_OK) {
Toast.makeText(this, R.string.cancelled, Toast.LENGTH_SHORT).show()
} else {
val fragment = supportFragmentManager.findFragmentById(R.id.container)
if (data != null && fragment is HomeFragment) {
fragment.handleRegister(data)
}
}
}
REQUEST_FIDO2_SIGNIN -> {
val errorExtra = data?.getByteArrayExtra(Fido.FIDO2_KEY_ERROR_EXTRA)
if (errorExtra != null) {
val error = AuthenticatorErrorResponse.deserializeFromBytes(errorExtra)
error.errorMessage?.let { errorMessage ->
Toast.makeText(this, errorMessage, Toast.LENGTH_LONG).show()
Log.e(TAG, errorMessage)
}
} else if (resultCode != RESULT_OK) {
Toast.makeText(this, R.string.cancelled, Toast.LENGTH_SHORT).show()
} else {
val fragment = supportFragmentManager.findFragmentById(R.id.container)
if (data != null && fragment is AuthFragment) {
fragment.handleSignin(data)
}
}
}
else -> super.onActivityResult(requestCode, resultCode, data)
}
}

override fun onResume() {
super.onResume()
viewModel.setFido2ApiClient(Fido.getFido2ApiClient(this))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2020 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.example.android.fido2.api

class ApiResult<T>(

/**
* The session ID to be used for the subsequent API calls. Might be null if the API call does
* not return a new cookie.
*/
val sessionId: String?,

/**
* The result data.
*/
val data: T
)
Loading

0 comments on commit ac04b3e

Please sign in to comment.