I am using sign in with Slack API
.
To obtain an access token, there is a HTTP GET request:
This is authorize url, I use this for login and implemented via WebView
:
I am using WebView
for login integration.
My classes are:
public class LoginApiClient {
private static LoginService loginService;
public static LoginService getLoginService(){
if (loginService != null){
Retrofit retrofitClient = new Retrofit.Builder()
.baseUrl("https://slack.com/")
.addConverterFactory(GsonConverterFactory.create())
.build();
loginService = retrofitClient.create(LoginService.class);
}
return loginService;
}
}
public interface LoginService {
@FormUrlEncoded
@GET("api/oauth.access")
Call<LoginResponse> makeUserLogin(@FieldMap Map<String, String > parameter);
}
public class LoginResponse {
.....
@SerializedName("access_token")
@Expose
private String accessToken;
.....
public String getAccessToken() {
return accessToken;
}
public void setAccessToken(String accessToken) {
this.accessToken = accessToken;
}
}
In my activity class, inside shouldOverrideUrlLoading
method:
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.startsWith("http://localhost:8000/")) {
UrlQuerySanitizer urlQuerySanitizer = new UrlQuerySanitizer(url);
codeParams = urlQuerySanitizer.getValue("code");
Log.e(TAG, "shouldOverrideUrlLoading: " + codeParams);
retrieveToken();
return true;
} else {
view.loadUrl(url);
return true;
}
}
private void retrieveToken() {
LoginService loginService = LoginApiClient.getLoginService();
Map<String, String> urlParameter = new HashMap<>();
urlParameter.put("client_id", StringConstant.CLIENT_ID);
urlParameter.put("client_secret", StringConstant.CLIENT_SECRET);
urlParameter.put("code", codeParams);
Call<LoginResponse> call = loginService.makeUserLogin(urlParameter);
call.enqueue(new Callback<LoginResponse>() {
@Override
public void onResponse(Call<LoginResponse> call, Response<LoginResponse> response) {
//navigate to next activity after saving token
}
@Override
public void onFailure(Call<LoginResponse> call, Throwable t) {
}
});
}
Now, it is throwing the nullpointer error and I think the request url not working, so I get this.
java.lang.NullPointerException: Attempt to invoke interface method 'retrofit2.Call com.loginApi.LoginService.makeUserLogin(java.util.Map)' on a null object reference
How can I know that, the HTTP GET request url is hitting ? How can I do to build the url and after login it get hit and I get token ?