Skip to content

Commit

Permalink
RATT added
Browse files Browse the repository at this point in the history
  • Loading branch information
revant committed Jul 28, 2017
1 parent 1a7431a commit 24ea2c9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 55 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.mntechnique.otpmobileauth.auth

import android.accounts.Account
import android.accounts.AccountManager
import android.accounts.AccountManagerCallback
import android.accounts.AccountManagerFuture
import android.content.Context
import android.os.AsyncTask
import android.os.Bundle
import android.util.Log

import com.mntechnique.otpmobileauth.R

/**
* Created by revant on 28/7/17.
*/

class RetrieveAuthTokenTask(private val context: Context, private val callback: AuthReqCallback) : AsyncTask<String, Void, Void>() {

private val exception: Exception? = null
private var authToken: String? = null

override fun doInBackground(vararg urls: String): Void? {
var accounts: Array<Account>? = null
val am = AccountManager.get(context)
accounts = am.getAccountsByType(context.resources.getString(R.string.package_name))
if (accounts!!.size == 1) {
val account = accounts[0]
am.getAuthToken(account, AccountGeneral.AUTHTOKEN_TYPE_FULL_ACCESS, null, true, { future ->
try {
val bundle = future.result
authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN)
callback.onSuccessResponse(authToken!!)
am.invalidateAuthToken(account.type, authToken)
} catch (e: Exception) {
Log.d("error", e.message)
callback.onErrorResponse(e.toString())
}
}, null)
} else {
Log.d("Accounts", "NOT 1 account found!")
}
return null
}
}

0 comments on commit 24ea2c9

Please sign in to comment.