Search in sources :

Example 1 with Credentials

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());
}
Also used : SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) GrantedAuthority(org.springframework.security.core.GrantedAuthority) ArrayList(java.util.ArrayList) InsufficientAuthenticationException(org.springframework.security.authentication.InsufficientAuthenticationException) DecodedJWT(com.auth0.jwt.interfaces.DecodedJWT) Claim(com.auth0.jwt.interfaces.Claim)

Example 2 with Credentials

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());
}
Also used : TextView(android.widget.TextView) Paint(android.graphics.Paint) Credentials(com.auth0.android.result.Credentials)

Example 3 with Credentials

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);
        }
    }
}
Also used : TextView(android.widget.TextView) Credentials(com.auth0.android.result.Credentials)

Example 4 with Credentials

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);
}
Also used : NavigationView(android.support.design.widget.NavigationView) RequestMethod(com.se491.chef_ly.http.RequestMethod) Bundle(android.os.Bundle) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) ViewPager(android.support.v4.view.ViewPager) NavigationView(android.support.design.widget.NavigationView) SearchView(android.support.v7.widget.SearchView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) Paint(android.graphics.Paint) RecipeList(com.se491.chef_ly.model.RecipeList) DrawerLayout(android.support.v4.widget.DrawerLayout) Credentials(com.auth0.android.result.Credentials) Toolbar(android.support.v7.widget.Toolbar)

Example 5 with Credentials

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");
        }
    });
}
Also used : Auth0(com.auth0.android.Auth0) AuthenticationException(com.auth0.android.authentication.AuthenticationException) AuthCallback(com.auth0.android.provider.AuthCallback) Dialog(android.app.Dialog) Credentials(com.auth0.android.result.Credentials)

Aggregations

Credentials (com.auth0.android.result.Credentials)4 TextView (android.widget.TextView)3 Paint (android.graphics.Paint)2 Dialog (android.app.Dialog)1 Bundle (android.os.Bundle)1 NavigationView (android.support.design.widget.NavigationView)1 ViewPager (android.support.v4.view.ViewPager)1 DrawerLayout (android.support.v4.widget.DrawerLayout)1 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)1 SearchView (android.support.v7.widget.SearchView)1 Toolbar (android.support.v7.widget.Toolbar)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 Auth0 (com.auth0.android.Auth0)1 AuthenticationException (com.auth0.android.authentication.AuthenticationException)1 AuthCallback (com.auth0.android.provider.AuthCallback)1 Claim (com.auth0.jwt.interfaces.Claim)1 DecodedJWT (com.auth0.jwt.interfaces.DecodedJWT)1 RequestMethod (com.se491.chef_ly.http.RequestMethod)1 RecipeList (com.se491.chef_ly.model.RecipeList)1