0

I have been trying to learn how to use Aqueduct's authorization but I am struggling with some errors. I found this question (OAuth Error using Aqueduct, mismatched ManagedPropertyType), which solved the first error saying it was expecting a string while an _ImmutableList was being passed. Nevertheless, whenever I make a the following POST request:

Future main() async {
  var http2 = new http.Client();
  var clientID = "com.wildfire.mobile";
  var clientSecret = "myspecialsecret ";
  var body = "username=usr&password=pwd&grant_type=password";
  var clientCredentials = new Base64Encoder().convert(
      "$clientID:$clientSecret".codeUnits);
  var response = await
  http.post(
      "http://localhost:8081/register",
      headers: {
        "Content-Type": "application/x-www-form-urlencoded",
        "Authorization": "Basic $clientCredentials"
      },
      body: body);

I get a 500 error as a response and the following exception:

 NoSuchMethodError: The getter 'credentials' was called on null.

in

 request.authorization.credentials.username

Nevertheless, in the _user table I see an entry for the user I registered. Should I juts ignore the error or is there someway to solve this issue?

Edit: It was indeed a misconfiguration issue. After deleting all my databases, I added a database.yaml file, which I thought was the same as the config.yaml but apparently is not.

1 Answers1

1

Credentials will be null if the request doesn't pass through an Authorizer. In this case, you'll want a basic authorizer:

router
  .route("/register")
  .pipe(new Authorizer.basic(authServer))
  .generate(() => new RegisterController());
Joe Conway
  • 1,566
  • 9
  • 8
  • Then should I modify the request? Because otherwise I get a 401. – Adan Villarreal Aug 23 '17 at 23:43
  • Sounds like something is misconfigured and it is also causing the issue in your other question (https://stackoverflow.com/questions/45809125/invalid-client-in-aqueducts-db-and-auth-wildfire-example) - I'm guessing that config.yaml has the wrong database. When configured correctly, an Authorizer will parse the Authorization request header, verify the credentials, and create and attach an Authorization object to the request. – Joe Conway Aug 24 '17 at 01:09