【Static Web Apps】GetRoles function not working

matsunotsuma 20 Reputation points
2024-09-15T08:57:58.2+00:00

Hi,

I'm developing static web application with react and Java(Spring Boot).

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?

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();

}

}

/.auth/me

image

I viewed this manual, but problem is not solved.

https://learn.microsoft.com/en-us/azure/static-web-apps/authentication-custom?tabs=aad%2Cinvitations

Best Regard.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,110 questions
Azure Static Web Apps
Azure Static Web Apps
An Azure service that provides streamlined full-stack web app development.
968 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
22,117 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.