authProviderName = Constants.GITHUB;
} else if (authProvider.equalsIgnoreCase(Constants.SAMSUNG)) {
authProviderName = Constants.SAMSUNG;
+ } else if (authProvider.equalsIgnoreCase(Constants.GOOGLE))
+ authProviderName = Constants.GOOGLE;
+ else {
+ Log.w("Unsupported oauth provider : " + authProvider);
}
return authProviderName;
options);
Log.d("access token : " + tokenInfo.getAccesstoken());
Log.d("refresh token : " + tokenInfo.getRefreshtoken());
- Log.d("expired time" + tokenInfo.getExpiredtime());
+ Log.d("expired time : " + tokenInfo.getExpiredtime());
return tokenInfo;
}
// find record about uuid and did
HashMap<String, Object> condition = new HashMap<>();
condition.put(Constants.KEYFIELD_UUID, uuid);
+ condition.put(Constants.KEYFIELD_DID, did);
ArrayList<HashMap<String, Object>> recordList = findRecord(
AccountDBManager.getInstance()
HashMap<String, Object> record = recordList.get(0);
TokenTable oldTokenInfo = castMapToTokenTable(record);
+ String provider = oldTokenInfo.getProvider();
if (!checkRefreshTokenInDB(oldTokenInfo, refreshToken)) {
throw new NotFoundException("refresh token is not correct");
}
// call 3rd party refresh token method
- TokenTable newTokenInfo = requestRefreshToken(refreshToken);
+ TokenTable newTokenInfo = requestRefreshToken(refreshToken, provider);
// record change
oldTokenInfo.setAccesstoken(newTokenInfo.getAccesstoken());
return response;
}
- private TokenTable requestRefreshToken(String refreshToken) {
+ private TokenTable requestRefreshToken(String refreshToken,
+ String provider) {
+
+ if (mFactory == null) {
+
+ boolean res = false;
+ String authProvider = checkAuthProviderName(provider);
+ res = loadAuthProviderLibrary(authProvider);
+
+ if (!res) {
+ throw new InternalServerErrorException(
+ authProvider + " library is not loaded");
+ }
+ }
TokenTable tokenInfo = mFactory.requestRefreshTokenInfo(refreshToken);
Once you get samples which file name is 'aircon_controlee' and 'aircon_controller', you need 'Auth Code' to register resources on cloud with account scenario.
-Cloud stack has sample github oauth2 adaptor.
+Cloud stack has sample github and google oauth2 adaptor.
So you can instantly test samples using 'Auth Code'.
Paste below URL to your browser
-https://github.com/login?return_to=%2Flogin%2Foauth%2Fauthorize%3Fclient_id%3Dea9c18f540323b0213d0%26redirect_uri%3Dhttp%253A%252F%252Fwww.example.com%252Foauth_callback%252F
+[Github] https://github.com/login?return_to=%2Flogin%2Foauth%2Fauthorize%3Fclient_id%3Dea9c18f540323b0213d0%26redirect_uri%3Dhttp%253A%252F%252Fwww.example.com%252Foauth_callback%252F
+[Google] https://accounts.google.com/o/oauth2/v2/auth?redirect_uri=http://www.example.com/oauth2callback&prompt=consent&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile&response_type=code&client_id=447649044559-f9r5sl6op3kkk0312u384o4g6hhucje1.apps.googleusercontent.com&access_type=offline
-And you'll see login page provided by github, and after logged in, you'll be redirectd to below site.
+And you'll see login page provided by oauth2 providers, and after logged in, you'll be redirectd to below site.
http://www.example.com/oauth_callback/?code=bf9beb5db17ea476fa46