Forum Xamarin.Forms

How to Apply Role base authorization in xamarin forms

saidtamimsaidtamim Member ✭✭
edited August 2020 in Xamarin.Forms

**In order to control which user have permission to access a page in the application like in web application we can control that by user roles
in the controller or in pege.cs file in razor pages we do it like

[Authorize(Roles = "Manager,Administrator")]
public class DocumentsController : Controller
{
//Action methods
}

, how to do this authorization in xamarin forms**

Best Answer

Answers

  • LandLuLandLu Member, Xamarin Team Xamurai
    Accepted Answer

    Try to verify the role before navigating like:

    if (role == "Administrator" &&  role == "Manager")
    {
        //Navigation.PushAsync();
    }
    else
    {
        //DisplayAlert();
    }
    

    As I posted here:
    https://forums.xamarin.com/discussion/184183/control-access-of-the-user

  • saidtamimsaidtamim Member ✭✭

    @LandLu said:
    Try to verify the role before navigating like:

    if (role == "Administrator" &&  role == "Manager")
    {
        //Navigation.PushAsync();
    }
    else
    {
        //DisplayAlert();
    }
    

    As I posted here:
    https://forums.xamarin.com/discussion/184183/control-access-of-the-user

    Thank you @LandLu

  • saidtamimsaidtamim Member ✭✭

    @LandLu said:
    Try to verify the role before navigating like:

    if (role == "Administrator" &&  role == "Manager")
    {
        //Navigation.PushAsync();
    }
    else
    {
        //DisplayAlert();
    }
    

    As I posted here:
    https://forums.xamarin.com/discussion/184183/control-access-of-the-user

    In case if we have multilevel pages and controls than how to manage that for example

    admin user have the full access to the all pages
    1) Main page
    1.1) Save Idea page
    1.1.1) Edit Idea
    1.1.2) Delete Idea
    1.2 Report Page

    new if I want a user to access only to delete Ideas than I have to check the user role in every level (1 Main page and 1.1.2 delete idea page) ???
    Or
    If a user have only access to the report page than

  • LandLuLandLu Member, Xamarin Team Xamurai

    I have to check the user role in every level

    Yes. Each time you want to navigate to a role page, you need to check the verification first before the navigation.

Sign In or Register to comment.