1
votes

I developed a module for Dotnetnuke(8) with WebAPI 2 Endpoints via the DNN API This API is consumed by an Android-App. To access the functions that are populated via the API, the user needs to authenticate.

I have already implemented the JWT (Json Web Token) Authentication with the WebAPI and login with username/password from the App works fine with this method.

Now I also want to allow users to login via their facebook-login and to get their name and email and photo from their facebook profile to authenticate and authorize them via the DNN-Users-Database and allow/disallow them to use the API functions.

I googled around a lot and read a lot of blogposts and articles about external authentication in the last few days. The following are very interesting and already gave me ann good insight how the process may work:

http://bitoftech.net/2014/08/11/asp-net-web-api-2-external-logins-social-logins-facebook-google-angularjs-app/

Registering Web API 2 external logins from multiple API clients with OWIN Identity

https://www.asp.net/web-api/overview/security/external-authentication-services

but I cannot really find out (and it seems i do not really understand) if and how this can be made working with my dnn-API and the JSON-WebToken Auth Method in my project.

If anybody can help to get me in the right direction, your help is highly appreciated. Thanks in advance and kind regards

Don

EDIT: The DNN-API gives all the JWT-Functionality I just need to define the api paths and functions. e.g: '

    <Route("{controller}/{action}/{p1}")>
    <AcceptVerbs("GET")>
    <AllowAnonymous>
    Public Function userInf(ByVal p1 As String) As HttpResponseMessage
        Dim response As New HttpResponseMessage
        Dim pID As Integer = DotNetNuke.Entities.Portals.PortalController.Instance.GetCurrentPortalSettings.PortalId
        Dim objUserInfo As New DotNetNuke.Entities.Users.UserInfo
        objUserInfo = DotNetNuke.Entities.Users.UserController.Instance.GetUserById(pID, CInt(p1))
        If Not objUserInfo Is Nothing Then
            If objUserInfo.UserID > 0 Then
                response = Request.CreateResponse(System.Net.HttpStatusCode.OK, JsonConvert.SerializeObject("Username: " & objUserInfo.Username.ToString))
            Else
                ' Not logged in
                response = Request.CreateResponse(System.Net.HttpStatusCode.Unauthorized, "Not found")
            End If
        Else
            ' Not logged in
            response = Request.CreateResponse(System.Net.HttpStatusCode.Unauthorized, "Not logged in")
        End If

        response.Headers.Add("Access-Control-Allow-Origin", CORS)                        ' <- Allow CORs !!!!
        ' response.Headers.Add("Access-Control-Request-Method", "*")
        Return response
    End Function 

The Api Path for the DNN Web-API is for authentication: example.com/DesktopModules/JwtAuth/API/mobile/Login where I pass the username and password in the request-body as a json-object (Documentation on dnnsoftware[dot]com / docs / administrators / jwt /)

This all works as expected. The thing now is how to make work the facebook login as an external login work together with my JWT-AUTH

1

1 Answers

0
votes

Web api doing authentication by itself, yout need to create OAuthAuthorizationServerOptions and configure web api to use methods, there is an example of how web api token based auth works with standart Bearer token.

There ApplicationOAuthProvider its a class which generates token for inhereting from OAuthAuthorizationServerProvider.

To call method from your token generator you need to get to the path /api/token and request will automaticly give you token and user Claims, which you will define in your token generator.

   public void ConfigureOAuth(IAppBuilder app)
    {
        OAuthBearerOptions = new OAuthBearerAuthenticationOptions();

        var oauthServerOptions = new OAuthAuthorizationServerOptions()
        {
            AllowInsecureHttp = true,
            TokenEndpointPath = new PathString("/api/token"),
            AccessTokenExpireTimeSpan = TimeSpan.FromHours(24),
            Provider = new ApplicationOAuthProvider(),
        };

        // Token Generation
        app.UseOAuthAuthorizationServer(oauthServerOptions);
        app.UseOAuthBearerAuthentication(OAuthBearerOptions);
    }

Hope this help.