0

I've Created Http Trigger Azure Java Functions, Function Name 1.FUNCTION (FUNCTION LEVEL Authorization)

,,, package com.function;

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;

import java.util.Optional;

/**
 * Azure Functions with HTTP Trigger.
 */
public class Function {
    /**
     * This function listens at endpoint "/api/HttpExample". Two ways to invoke it using "curl" command in bash:
     * 1. curl -d "HTTP Body" {your host}/api/HttpExample
     * 2. curl "{your host}/api/HttpExample?name=HTTP%20Query"
     */
    @FunctionName("FUNCTION")
    public HttpResponseMessage run(
            @HttpTrigger(
                name = "req",
                methods = {HttpMethod.GET, HttpMethod.POST},
                authLevel = AuthorizationLevel.FUNCTION)
                HttpRequestMessage<Optional<String>> request,
            final ExecutionContext context) {
        context.getLogger().info("Java HTTP trigger processed a request.");

        // Parse query parameter
        final String query = request.getQueryParameters().get("name");
        final String name = request.getBody().orElse(query);



        if (name == null) {
                return request.createResponseBuilder(HttpStatus.BAD_REQUEST).body("Please pass a name on the query string or in the request body").build();
            }

    else {
                return request.createResponseBuilder(HttpStatus.OK).body("Hello, " + name).build();
        
                }
        }
    }

,,,

Above Function Having Function Auth. Successfully Deployed to Function app and I've Updated Host Key& Value

In Function App:

host key& value in Function App Image

But This Function Not Working In Postman Even I use Host key and Value

In Header Section Through Postman

Function Error Screenshot in Postman

Postman Error: 401Unauthorized

Please Guide me is it right way to use FUNCTION Level Authorization For azure Java Function or need to ADD/change any Things in Code/Function App Level?

1 Answer 1

1
  • Well if you go to Functions tab and click on the function which you have deployed.

enter image description here

  • Then click on the get function url tab and copy the url .

enter image description here

  • Now this URl would include the function key which can be used for auth

PostMan output enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

Hi Mohit, please read my question again.... I m asking Authorization not working

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.