I'm trying to use auth framework with REST api ( http://vibed.org/api/vibe.web.auth/ ).

Is it possible to use it with registerRestInterface? According to description under: http://vibed.org/api/vibe.web.auth/requiresAuth it should be available on both Web and REST.

Here is my example code and compilation errors bellow:

import vibe.d;
import vibe.web.auth;
import vibe.http.session;
import vibe.web.rest : registerRestInterface;
import vibe.web.web : noRoute;
import std.algorithm, std.array;

struct AuthInfo {
        string userName;
    bool premium;
    bool admin;

        bool isAdmin() { return this.admin; }
        bool isPremiumUser() { return this.premium; }

interface IfOAuthAPI
    void postLogin(ValidUsername login, ValidPassword password);
//    bool postTokenValidation(string token, string userName);

class OAuthAPI : IfOAuthAPI

AuthInfo authenticate(scope HTTPServerRequest req, scope HTTPServerResponse res) @safe
                if (!req.session || !req.session.isKeySet("auth"))
throw new HTTPStatusException(HTTPStatus.forbidden, "Not authorized to perform this action!");

                return req.session.get!AuthInfo("auth");

  this(MongoCollection coll)
    collection = coll;

    MongoCollection collection;

    string postLogin(ValidUsername login, ValidPassword password)
      logInfo("Recived data for" ~ login ~ "and" ~ password);

      Bson query = Bson(["username" : Bson(login)]);
      auto result = collection.find(query);

      foreach (i, doc; result)
        logInfo("Item %d: %s", i, doc.toJson().toString());

      logInfo("Sending respond");
      return "OK";


And im getting such errors:

ms-frontpage ~master: building configuration "application"...
Deprecation: alias diet.traits.FilterCallback is deprecated - Use 
SafeFilterCallback instead.
source/app.d(14,31): Error: cannot create instance of interface IfOAuthAPI source/service/oauth.d(35,8): Error: @safe function 'oauth.OAuthAPI.authenticate' cannot call @system function 'vibe.http.session.Session.opCast' source/service/oauth.d(35,44): Error: @safe function 'oauth.OAuthAPI.authenticate' cannot call @system function 'vibe.http.session.Session.isKeySet' source/service/oauth.d(36,10): Error: @safe function 'oauth.OAuthAPI.authenticate' cannot call @system constructor 'vibe.http.common.HTTPStatusException.this' source/service/oauth.d(38,34): Error: @safe function 'oauth.OAuthAPI.authenticate' cannot call @system function 'vibe.http.session.Session.get!(AuthInfo).get'
dmd failed with exit code 1.


Reply via email to