use of com.auth0.android.result.Credentials in project libresonic by Libresonic.
the class JWTAuthenticationProvider method authenticate.
@Override
public Authentication authenticate(Authentication auth) throws AuthenticationException {
JWTAuthenticationToken authentication = (JWTAuthenticationToken) auth;
if (authentication.getCredentials() == null || !(authentication.getCredentials() instanceof String)) {
logger.error("Credentials not present");
return null;
}
String rawToken = (String) auth.getCredentials();
DecodedJWT token = JWTSecurityService.verify(jwtKey, rawToken);
Claim path = token.getClaim(JWTSecurityService.CLAIM_PATH);
authentication.setAuthenticated(true);
// TODO:AD This is super unfortunate, but not sure there is a better way when using JSP
if (StringUtils.contains(authentication.getRequestedPath(), "/WEB-INF/jsp/")) {
logger.warn("BYPASSING AUTH FOR WEB-INF page");
} else if (!roughlyEqual(path.asString(), authentication.getRequestedPath())) {
throw new InsufficientAuthenticationException("Credentials not valid for path " + authentication.getRequestedPath() + ". They are valid for " + path.asString());
}
List<GrantedAuthority> authorities = new ArrayList<>();
authorities.add(new SimpleGrantedAuthority("IS_AUTHENTICATED_FULLY"));
authorities.add(new SimpleGrantedAuthority("ROLE_TEMP"));
return new JWTAuthenticationToken(authorities, rawToken, authentication.getRequestedPath());
}
use of com.auth0.android.result.Credentials in project chefly_android by chef-ly.
the class MainActivity method onLoadFinished.
// LoaderManager callback method
@Override
public void onLoadFinished(Loader<RecipeList> loader, RecipeList data) {
int id = loader.getId();
if (id == RECIPELISTID) {
serverRecipes = data;
splashHandler.removeCallbacksAndMessages(null);
setContentView(R.layout.activity_main);
setupViews();
Credentials credentials = CredentialsManager.getCredentials(this);
if (credentials.getAccessToken() != null) {
if (credentials.getExpiresIn() > 0) {
TextView skip = (TextView) findViewById(R.id.continueAsGuest);
String name = CredentialsManager.getUsername(this);
String msg = getString(R.string.welcomeback) + (name != null ? " " + name : "");
skip.setText(msg);
skip.setPaintFlags(skip.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
}
}
}
Log.d(TAG, "OnLoadFinished " + loader.getId());
}
use of com.auth0.android.result.Credentials in project chefly_android by chef-ly.
the class MainActivity method onResume.
@Override
protected void onResume() {
super.onResume();
Credentials credentials = CredentialsManager.getCredentials(this);
TextView skip = (TextView) findViewById(R.id.continueAsGuest);
if (skip != null) {
if (credentials.getAccessToken() == null) {
skip.setText(getString(R.string.continueAsGuest));
skip.setPaintFlags(skip.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
} else {
String name = CredentialsManager.getUsername(this);
String msg = getString(R.string.welcomeback) + (name != null ? " " + name : "");
skip.setText(msg);
skip.setPaintFlags(skip.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
}
}
}
use of com.auth0.android.result.Credentials in project chefly_android by chef-ly.
the class RecipeListActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recipe_list);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
//Initialize recipe lists
serverRecipes = new RecipeList();
favoriteRecipes = new RecipeList();
//Start AsyncTaskLoader to get FavoriteRecipes
Credentials cred = CredentialsManager.getCredentials(getApplicationContext());
String t = cred.getAccessToken();
Log.d(TAG, "Token -> " + t);
if (t != null) {
RequestMethod requestPackageFavs = new RequestMethod();
requestPackageFavs.setEndPoint(urlFavsString);
requestPackageFavs.setMethod("GET");
requestPackageFavs.setHeader("Authorization", "Bearer " + t);
Bundle bundlefavs = new Bundle();
bundlefavs.putParcelable("requestPackage", requestPackageFavs);
getSupportLoaderManager().initLoader(FAVORTIESID, bundlefavs, this).forceLoad();
} else {
Toast.makeText(this, "Could not retrieve favorites, token is null", Toast.LENGTH_SHORT).show();
}
// PageViewer
pager = (ViewPager) findViewById(R.id.viewpager);
Bundle serv = new Bundle();
serv.putString("title", "Recipes");
serv.putString("pageNum", "1");
serv.putString("search", "");
server = new ListViewFragment();
server.setArguments(serv);
Bundle f = new Bundle();
f.putString("title", "Favorites");
f.putString("pageNum", "2");
f.putString("search", "");
favs = new ListViewFragment();
favs.setArguments(f);
ListViewFragment[] frags = { server, favs };
pager.setAdapter(new RecipeListPagerAdapter(getSupportFragmentManager(), frags));
pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
//Log.d(TAG, "Position -> " + position);
if (position == 1) {
favoritesHeader.setPaintFlags(favoritesHeader.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
recipesHeader.setPaintFlags(0);
// ingredientsHeader.setPaintFlags(0);
} else {
recipesHeader.setPaintFlags(recipesHeader.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
favoritesHeader.setPaintFlags(0);
// ingredientsHeader.setPaintFlags(0);
}
}
@Override
public void onPageSelected(int position) {
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
// Header links
// ingredientsHeader = (TextView) findViewById(R.id.ingredientsHeader);
favoritesHeader = (TextView) findViewById(R.id.favortiesHeader);
recipesHeader = (TextView) findViewById(R.id.recipesHeader);
View.OnClickListener headerListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
if (v.getId() == favoritesHeader.getId()) {
favoritesHeader.setPaintFlags(favoritesHeader.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
recipesHeader.setPaintFlags(0);
// ingredientsHeader.setPaintFlags(0);
pager.setCurrentItem(1);
} else {
recipesHeader.setPaintFlags(recipesHeader.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
favoritesHeader.setPaintFlags(0);
// ingredientsHeader.setPaintFlags(0);
pager.setCurrentItem(0);
}
}
};
// ingredientsHeader.setOnClickListener(headerListener);
favoritesHeader.setOnClickListener(headerListener);
recipesHeader.setOnClickListener(headerListener);
//Tool/Appbar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// Navigation Drawer
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
use of com.auth0.android.result.Credentials in project chefly_android by chef-ly.
the class MainActivity method socialLogin.
private void socialLogin(String connection) {
//getString(R.string.auth0_domain
Auth0 auth0 = new Auth0(getString(R.string.auth0_client_id), getString(R.string.auth0_domain));
WebAuthProvider.init(auth0).withConnection(connection).start(MainActivity.this, new AuthCallback() {
@Override
public void onFailure(@NonNull Dialog dialog) {
dialog.show();
}
@Override
public void onFailure(final AuthenticationException exception) {
//Show error to the user
runOnUiThread(new Runnable() {
@Override
public void run() {
Log.d(TAG, "LOGIN FAIL");
String errorMsg = "Sign in request failed";
showToast(errorMsg);
}
});
}
@Override
public void onSuccess(@NonNull Credentials credentials) {
// Navigate to your next activity
startRecipeListActivity("aaa");
}
});
}
Aggregations