This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Bad practice: Hardcoded UserName and Password | |
String username ="admin" | |
String password ="p@ssw0rd" | |
# Good practice: Retrive credential from a secure source | |
String username = CredentialManager.getUsername() | |
String password =CredentialManager.getPassword() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Singleton | |
@Provides | |
fun provideOkhttpClient(authInterceptor: AuthInterceptor, | |
certificateHelper: CertificateHelper | |
) :OkHttpClient{ | |
val trustManagers = certificateHelper.createTrustManagers() | |
val sslContext = SSLContext.getInstance("TLS") | |
sslContext.init(null, trustManagers, null) | |
return OkHttpClient().newBuilder() | |
.readTimeout(2, TimeUnit.MINUTES) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FirebaseAuth mAuth = FirebaseAuth.getInstance(); | |
// Sign in with email and password | |
mAuth.signInWithEmailAndPassword(email, password) | |
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { | |
@Override | |
public void onComplete(@NonNull Task<AuthResult> task) { | |
if (task.isSuccessful()) { | |
// User is authenticated | |
} else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
buildTypes { | |
release { | |
buildConfigField "String", "BASE_URL", "\"https://mbl.test.com\"" | |
minifyEnabled true | |
shrinkResources true | |
debuggable false | |
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), | |
'proguard-rules.pro' | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CertificateHelper @Inject constructor(@ApplicationContext context: Context) { | |
private val applicationContext = context | |
fun createTrustManagers(): Array<TrustManager> { | |
val certificateInputStream = applicationContext.resources.openRawResource( | |
R.raw.test) | |
val certificateFactory = CertificateFactory.getInstance("X.509") | |
val certificate = certificateFactory.generateCertificate(certificateInputStream) | |
val trustManagerFactory = TrustManagerFactory.getInstance( | |
TrustManagerFactory.getDefaultAlgorithm()) | |
val keyStore = KeyStore.getInstance(KeyStore.getDefaultType()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (!usbManager!!.hasPermission(usbDevice)) { | |
usbManager!!.requestPermission(usbDevice, mPendingIntent) | |
} |