diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LoginWebviewFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LoginWebviewFragment.kt index 0b30d402..5c09e7a4 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LoginWebviewFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LoginWebviewFragment.kt @@ -198,27 +198,28 @@ class LoginWebviewFragment : Fragment() { } private fun initiateAuthentication(authCode: String) { - mPlatform?.getAccessToken(authCode, - - "authorization_code", clientID, redirectUri, codeVerifier, - object : Callback { - - override fun success(t: AccessTokenResponse?, response: Response?) { - if (response?.status == 200) { - val accessToken = t?.accessToken - val editor = sp.edit() - editor.putString(getString(R.string.access_token), accessToken) - editor.putString(getString(R.string.refresh_token), t?.refreshToken) - editor.putString(getString(R.string.expires_in), t?.expiresIn) - - val expiresInInt = t?.expiresIn!!.toInt() * 1000 - Log.i("LoginWebview", "Expires In: $expiresInInt") - val currentTime = Calendar.getInstance().timeInMillis - editor.putLong(getString(R.string.token_expires_at), currentTime + expiresInInt) - editor.apply() - getUser(accessToken) - } + mStudentLife.getAccessToken(authCode, + + "authorization_code", clientID, redirectUri, codeVerifier, + object : Callback { + + override fun success(t: AccessTokenResponse?, response: Response?) { + if (response?.status == 200) { + val accessToken = t?.accessToken + val editor = sp.edit() + editor.putString(getString(R.string.access_token), accessToken) + editor.putString(getString(R.string.refresh_token), t?.refreshToken) + editor.putString(getString(R.string.expires_in), t?.expiresIn) + + val expiresInInt = t?.expiresIn!!.toInt() * 1000 + Log.i("LoginWebview", "Expires In: $expiresInInt") + val currentTime = Calendar.getInstance().timeInMillis + editor.putLong(getString(R.string.token_expires_at), currentTime + expiresInInt) + editor.apply() + getUser(accessToken) } + } + override fun failure(error: RetrofitError) { Log.e("Accounts", "Error fetching access token $error", error) Toast.makeText(mActivity, "Error logging in", Toast.LENGTH_SHORT).show() diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/api/OAuth2NetworkManager.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/api/OAuth2NetworkManager.kt index 25f788ea..58137edb 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/api/OAuth2NetworkManager.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/api/OAuth2NetworkManager.kt @@ -14,7 +14,7 @@ import java.util.* class OAuth2NetworkManager(private var mActivity: MainActivity) { - private var mPlatform = MainActivity.platformInstance + private var mStudentLife = MainActivity.studentLifeInstance private val sp = PreferenceManager.getDefaultSharedPreferences(mActivity) val editor = sp?.edit() @@ -43,7 +43,7 @@ class OAuth2NetworkManager(private var mActivity: MainActivity) { val refreshToken = sp.getString(mActivity.getString(R.string.refresh_token), "") val clientID = BuildConfig.PLATFORM_CLIENT_ID - mPlatform.refreshAccessToken(refreshToken, + mStudentLife.refreshAccessToken(refreshToken, "refresh_token", clientID, object : Callback { @@ -92,7 +92,7 @@ class OAuth2NetworkManager(private var mActivity: MainActivity) { val refreshToken = sp.getString(mActivity.getString(R.string.refresh_token), "") val clientID = BuildConfig.PLATFORM_CLIENT_ID - mPlatform.refreshAccessToken(refreshToken, + mStudentLife.refreshAccessToken(refreshToken, "refresh_token", clientID, object : Callback { diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/api/StudentLife.java b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/api/StudentLife.java index d21ee551..89fc598d 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/api/StudentLife.java +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/api/StudentLife.java @@ -12,6 +12,7 @@ import com.pennapps.labs.pennmobile.classes.GSRBookingResult; import com.pennapps.labs.pennmobile.classes.GSRLocation; import com.pennapps.labs.pennmobile.classes.GSRReservation; +import com.pennapps.labs.pennmobile.classes.GetUserResponse; import com.pennapps.labs.pennmobile.classes.Gym; import com.pennapps.labs.pennmobile.classes.HomeCell; import com.pennapps.labs.pennmobile.classes.LaundryRequest; @@ -45,6 +46,17 @@ * Retrofit interface to the Penn Mobile API */ public interface StudentLife { + + @FormUrlEncoded + @POST("/accounts/token/") + void getAccessToken( + @Field("code") String authCode, + @Field("grant_type") String grantType, + @Field("client_id") String clientID, + @Field("redirect_uri") String redirectURI, + @Field("code_verifier") String codeVerifier, + Callback callback); + @FormUrlEncoded @POST("/accounts/token/") void refreshAccessToken(