Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetRoles not working #13

Open
matsunotsuma opened this issue Sep 1, 2024 · 1 comment
Open

GetRoles not working #13

matsunotsuma opened this issue Sep 1, 2024 · 1 comment

Comments

@matsunotsuma
Copy link

Hi,
I want to manage users with Entra ID and user roles with DB.
So I deployed SWA with custom authentication, but GetRoles Function is not working.
Can anyone detect the cause of this problem.

staticwebapp.config.json

{
    "auth": {
        "rolesSource": "/api/GetRoles",
        "identityProviders": {
            "azureActiveDirectory": {
                "registration": {
                    "openIdIssuer": "https://login.microsoftonline.com/-----------",
                    "clientIdSettingName": "AZURE_CLIENT_ID",
                    "clientSecretSettingName": "AZURE_CLIENT_SECRET_APP_SETTING_NAME"
                }
            }
        }
    },
    "navigationFallback": {
        "rewrite": "/index.html"
    },
    "routes": [
        {
            "route": "/client",
            "allowedRoles": ["CLIENT"]
        }
    ],
    "responseOverrides": {
        "401": {
        "statusCode": 302,
        "redirect": "/.auth/login/aad"
        }
    }

}

GetRoles Function (Java)

package com.ms.samples.demo.mscs_az_functions;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import org.springframework.stereotype.Component;

import com.microsoft.azure.functions.ExecutionContext;
import com.microsoft.azure.functions.HttpMethod;
import com.microsoft.azure.functions.HttpRequestMessage;
import com.microsoft.azure.functions.HttpResponseMessage;
import com.microsoft.azure.functions.HttpStatus;
import com.microsoft.azure.functions.annotation.AuthorizationLevel;
import com.microsoft.azure.functions.annotation.FunctionName;
import com.microsoft.azure.functions.annotation.HttpTrigger;


@Component
public class GetRoles {
    @FunctionName("GetRoles")
    public HttpResponseMessage run(
            @HttpTrigger(
                name = "req",
                methods = {HttpMethod.GET, HttpMethod.POST},
                authLevel = AuthorizationLevel.ANONYMOUS)
                HttpRequestMessage<Optional<String>> request,
            final ExecutionContext context) {
        context.getLogger().info("Java HTTP trigger processed a request.");


		//		レスポンスの作成
		Map<String, Object> responseBody = new HashMap<>();

        List<String> roles = new ArrayList<String>();
        roles.add("CLIENT");
        roles.add("ADMINISTRATOR");
        roles.add("GETROLES");
        responseBody.put("roles", roles);
        return request.createResponseBuilder(HttpStatus.OK).body(responseBody).build();
    }
}

local dev log
image

/.auth/me
image

Best Regard.

@JamieMair
Copy link

Same problem for me, even the base tutorial does not work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants