summaryrefslogtreecommitdiff
path: root/FireBase/Query/AuthQuery.cs
blob: 2cfda3cd2c508cb3855691874a15ffecd16e7e66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System;

namespace Firebase.Database.Query
{
    /// <summary>
    ///     Represents an auth parameter in firebase query, e.g. "?auth=xyz".
    /// </summary>
    public class AuthQuery : ParameterQuery
    {
        private readonly Func<string> tokenFactory;

        /// <summary>
        ///     Initializes a new instance of the <see cref="AuthQuery" /> class.
        /// </summary>
        /// <param name="parent"> The parent.  </param>
        /// <param name="tokenFactory"> The authentication token factory. </param>
        /// <param name="client"> The owner. </param>
        public AuthQuery(FirebaseQuery parent, Func<string> tokenFactory, FirebaseClient client) : base(parent,
            () => client.Options.AsAccessToken ? "access_token" : "auth", client)
        {
            this.tokenFactory = tokenFactory;
        }

        /// <summary>
        ///     Build the url parameter value of this child.
        /// </summary>
        /// <param name="child"> The child of this child. </param>
        /// <returns> The <see cref="string" />. </returns>
        protected override string BuildUrlParameter(FirebaseQuery child)
        {
            return tokenFactory();
        }
    }
}