Fix Authorization with fingerprint

This commit is contained in:
Bernat Borrás-Paronella Petit 2017-03-12 14:26:47 +01:00
parent 6dcb77f892
commit e4f87edccb
5 changed files with 48 additions and 25 deletions

View File

@ -0,0 +1,37 @@
package com.fastaccess.data;
import android.support.annotation.NonNull;
import com.fastaccess.data.dao.AccessTokenModel;
import com.fastaccess.data.dao.AuthModel;
import retrofit2.Response;
import retrofit2.http.Body;
import retrofit2.http.DELETE;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.Header;
import retrofit2.http.POST;
import retrofit2.http.PUT;
import retrofit2.http.Path;
import rx.Observable;
public interface LoginRestService {
@FormUrlEncoded
@POST("access_token")
Observable<AccessTokenModel> getAccessToken(@NonNull @Field("code") String code,
@NonNull @Field("client_id") String clientId,
@NonNull @Field("client_secret") String clientSecret,
@NonNull @Field("state") String state,
@NonNull @Field("redirect_uri") String redirectUrl);
@PUT("authorizations/clients/{clientId}/{fingerprint}") Observable<AccessTokenModel> login(@NonNull @Path("clientId") String clientId,
@NonNull @Path("clientId") String fingerprint,
@NonNull @Body AuthModel authModel);
@PUT("authorizations/clients/{clientId}/{fingerprint}") Observable<AccessTokenModel> login(@NonNull @Path("clientId") String clientId,
@NonNull @Path("clientId") String fingerprint,
@NonNull @Body AuthModel authModel,
@NonNull @Header("X-GitHub-OTP") String otpCode);
@DELETE("authorizations/{id}") Observable<Response<Boolean>> deleteToken(@Path("id") long id);
}

View File

@ -29,22 +29,6 @@ import rx.Observable;
public interface UserRestService {
@FormUrlEncoded @POST("access_token")
Observable<AccessTokenModel> getAccessToken(@NonNull @Field("code") String code,
@NonNull @Field("client_id") String clientId,
@NonNull @Field("client_secret") String clientSecret,
@NonNull @Field("state") String state,
@NonNull @Field("redirect_uri") String redirectUrl);
@PUT("authorizations/clients/{clientId}") Observable<AccessTokenModel> login(@NonNull @Path("clientId") String clientId,
@NonNull @Body AuthModel authModel);
@PUT("authorizations/clients/{clientId}") Observable<AccessTokenModel> login(@NonNull @Path("clientId") String clientId,
@NonNull @Body AuthModel authModel,
@NonNull @Header("X-GitHub-OTP") String otpCode);
@DELETE("authorizations/{id}") Observable<Response<Boolean>> deleteToken(@Path("id") long id);
@GET("user") Observable<LoginModel> getUser();
@GET("users/{username}") Observable<UserModel> getUser(@Path("username") @NonNull String username);

View File

@ -3,6 +3,7 @@ package com.fastaccess.provider.rest;
import android.support.annotation.NonNull;
import com.fastaccess.BuildConfig;
import com.fastaccess.data.LoginRestService;
import com.fastaccess.data.service.UserRestService;
import com.fastaccess.provider.rest.converters.GithubResponseConverter;
import com.fastaccess.provider.rest.interceptors.AuthenticationInterceptor;
@ -49,7 +50,7 @@ public class LoginProvider {
.build();
}
@NonNull public static UserRestService getLoginRestService(@NonNull String authToken) {
return provideRetrofit(authToken).create(UserRestService.class);
@NonNull public static LoginRestService getLoginRestService(@NonNull String authToken) {
return provideRetrofit(authToken).create(LoginRestService.class);
}
}

View File

@ -5,10 +5,10 @@ import android.content.Context;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.fastaccess.App;
import com.fastaccess.BuildConfig;
import com.fastaccess.R;
import com.fastaccess.data.LoginRestService;
import com.fastaccess.data.dao.GitHubErrorResponse;
import com.fastaccess.data.service.GistService;
import com.fastaccess.data.service.IssueService;
@ -25,9 +25,7 @@ import com.fastaccess.provider.rest.interceptors.PaginationInterceptor;
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.lang.reflect.Modifier;
import okhttp3.Cache;
import okhttp3.OkHttpClient;
import okhttp3.Request;
@ -117,14 +115,14 @@ public class RestProvider {
return -1;
}
@NonNull public static UserRestService getLoginRestService() {
@NonNull public static LoginRestService getLoginRestService() {
return new Retrofit.Builder()
.client(provideOkHttpClient(true))
.baseUrl("https://github.com/login/oauth/")
.addConverterFactory(GsonConverterFactory.create(gson))
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.build()
.create(UserRestService.class);
.create(LoginRestService.class);
}
@NonNull public static UserRestService getUserService() {

View File

@ -17,6 +17,7 @@ import com.fastaccess.ui.base.mvp.presenter.BasePresenter;
import java.util.Arrays;
import java.util.UUID;
import okhttp3.Credentials;
import retrofit2.adapter.rxjava.HttpException;
import rx.Observable;
@ -69,11 +70,13 @@ class LoginPresenter extends BasePresenter<LoginMvp.View> implements LoginMvp.Pr
authModel.setNote(BuildConfig.APPLICATION_ID + "-" + authToken);//make it unique to FastHub.
authModel.setClientSecret(BuildConfig.GITHUB_SECRET);
UUID uuid = UUID.randomUUID();
Observable<AccessTokenModel> loginCall =
LoginProvider.getLoginRestService(authToken).login(BuildConfig.GITHUB_CLIENT_ID, authModel);
LoginProvider.getLoginRestService(authToken).login(BuildConfig.GITHUB_CLIENT_ID, uuid.toString(), authModel);
if (twoFactorCode != null && !twoFactorCode.isEmpty()) {
loginCall = LoginProvider.getLoginRestService(authToken).login(BuildConfig.GITHUB_CLIENT_ID, authModel,
loginCall = LoginProvider.getLoginRestService(authToken).login(BuildConfig.GITHUB_CLIENT_ID, uuid.toString(), authModel,
twoFactorCode);
}