Beispiel #1
0
 /// <summary>
 /// Get Implicit Grant Auth - Implicit Grant Flow
 /// </summary>
 /// <param name="responseUri">Response Uri</param>
 /// <param name="redirectUri">Redirect Uri</param>
 /// <param name="state">State Value</param>
 /// <returns>Access Token</returns>
 /// <exception cref="AuthTokenValueException">AuthTokenValueException</exception>
 /// <exception cref="AuthTokenStateException">AuthTokenStateException</exception>
 public AccessToken GetImplicitGrantAuth(
     Uri responseUri,
     Uri redirectUri,
     string state)
 {
     if (responseUri != null)
     {
         if (responseUri.ToString().Contains(redirectUri.ToString()))
         {
             if (_implicitGrant == null || _implicitGrant.ResponseUri != responseUri)
             {
                 _implicitGrant = new ImplicitGrant(
                     responseUri, redirectUri,
                     responseUri.Fragment.TrimStart('#').QueryStringAsDictionary());
                 if (state == null || _implicitGrant.State == state)
                 {
                     if (string.IsNullOrEmpty(_implicitGrant.AccessToken))
                     {
                         throw new AuthTokenValueException();
                     }
                     else
                     {
                         return(Map(_implicitGrant));
                     }
                 }
                 else
                 {
                     throw new AuthTokenStateException();
                 }
             }
         }
     }
     return(null);
 }
Beispiel #2
0
 /// <summary>
 /// Map
 /// </summary>
 /// <param name="response">ImplicitGrant</param>
 /// <returns>Access Token</returns>
 private AccessToken Map(ImplicitGrant response) =>
 new AccessToken
 {
     TokenType  = TokenType.User,
     Token      = response.AccessToken,
     Expiration = DateTime.UtcNow.Add(
         TimeSpan.FromSeconds(Convert.ToDouble(
                                  response.ExpiresIn)))
 };