Skip to content

ricaun-io/firebase-functions-dotnet

Repository files navigation

FirebaseFunctions.net

Visual Studio 2019 Nuke License MIT Publish Develop Release

Firebase functions library for C# to work with https.onCall.

For Authenticating with Firebase checkout the Firebase Authentication library.

Installation

// Install release version
Install-Package FirebaseFunctions.net

Supported frameworks

Supported scenarios

Usage

Firebase.Functions

string FirebaseApiKey = "###########";
string FirebaseFunctions = "###########.cloudfunctions.net";
string FirebaseCallFunction = "Test";

var authProvider = new FirebaseAuthProvider(new FirebaseConfig(FirebaseApiKey));
var auth = await authProvider.SignInAnonymouslyAsync();

var functions = new FirebaseFunctions(FirebaseFunctions,
    new FirebaseFunctionsOptions()
    {
        AuthTokenAsyncFactory = () => Task.FromResult(auth.FirebaseToken),
    });

var function = functions.GetHttpsCallable(FirebaseCallFunction);

var response = await function.CallAsync();
Console.WriteLine($"Response: {response}");

Firebase Functions Test

exports.Test = functions.https.onCall((data, context) => {
    // check request is made by an admin
    if (context.auth.token.admin !== true) {
        return { message: 'This user is not admin.' }
    }
    return {
        message: `Admin success!`
    }
});

Release

License

This project is licensed under the MIT Licence.


Do you like this project? Please star this project on GitHub!