internal async Task <string> CreateSessionCookieAsync(
            string idToken,
            SessionCookieOptions options,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (string.IsNullOrEmpty(idToken))
            {
                throw new ArgumentException("idToken must not be null or empty");
            }

            var validOptions = options.ThrowIfNull(nameof(options)).CopyAndValidate();
            var request      = new Dictionary <string, object>()
            {
                { "idToken", idToken },
                { "validDuration", (long)validOptions.ExpiresIn.TotalSeconds },
            };
            var response = await this.PostAndDeserializeAsync <JObject>(
                ":createSessionCookie", request, cancellationToken).ConfigureAwait(false);

            if (response.Result == null || (string)response.Result["sessionCookie"] == null)
            {
                throw UnexpectedResponseException("Failed to generate session cookie");
            }

            return((string)response.Result["sessionCookie"]);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates a new Firebase session cookie from the given ID token and options. The returned JWT can
 /// be set as a server-side session cookie with a custom cookie policy.
 /// </summary>
 /// <exception cref="FirebaseAuthException">If an error occurs while creating the cookie.</exception>
 /// <param name="idToken">The Firebase ID token to exchange for a session cookie.</param>
 /// <param name="options">Additional options required to create the cookie.</param>
 /// <param name="cancellationToken">A cancellation token to monitor the asynchronous
 /// operation.</param>
 /// <returns>A task that completes with the Firebase session cookie.</returns>
 public async Task <string> CreateSessionCookieAsync(
     string idToken, SessionCookieOptions options, CancellationToken cancellationToken)
 {
     return(await this.UserManager
            .CreateSessionCookieAsync(idToken, options, cancellationToken)
            .ConfigureAwait(false));
 }
Ejemplo n.º 3
0
        internal SessionCookieOptions CopyAndValidate()
        {
            var copy = new SessionCookieOptions()
            {
                ExpiresIn = this.ExpiresIn,
            };

            if (copy.ExpiresIn < TimeSpan.FromMinutes(5))
            {
                throw new ArgumentException("ExpiresIn must be at least 5 minutes");
            }
            else if (copy.ExpiresIn > TimeSpan.FromDays(14))
            {
                throw new ArgumentException("ExpiresIn must be at most 14 days");
            }

            return(copy);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Creates a new Firebase session cookie from the given ID token and options. The returned JWT can
 /// be set as a server-side session cookie with a custom cookie policy.
 /// </summary>
 /// <exception cref="FirebaseAuthException">If an error occurs while creating the cookie.</exception>
 /// <param name="idToken">The Firebase ID token to exchange for a session cookie.</param>
 /// <param name="options">Additional options required to create the cookie.</param>
 /// <returns>A task that completes with the Firebase session cookie.</returns>
 public async Task <string> CreateSessionCookieAsync(
     string idToken, SessionCookieOptions options)
 {
     return(await this.CreateSessionCookieAsync(idToken, options, default(CancellationToken))
            .ConfigureAwait(false));
 }