Adan Villarreal
Adan Villarreal

Reputation: 33

Can't create account in aqueduct's db_and_auth/wildfire example

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.

Upvotes: 0

Views: 135

Answers (1)

Joe Conway
Joe Conway

Reputation: 1586

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

Upvotes: 1

Related Questions