internal bool VerifyCredentials() { lock (AuthLock) { if (AuthToken == null && ImplicitToken == null) { Authorize(); return(true); } else { if (!RequestedScopes.Contains(Scope.None) || ReauthorizeScopes) { Authorize(); return(true); } if (!IsTokenValid()) { RefreshAccessToken(); return(true); } } return(true); } }
public bool AreScopesValid(IEnumerable <string> requestedScopes, IEnumerable <Scope> availableScopes) { foreach (var requestedScope in requestedScopes) { var scopeDetail = availableScopes.FirstOrDefault(s => s.Name == requestedScope); if (scopeDetail == null) { Logger.ErrorFormat("Invalid scope: {0}", requestedScope); return(false); } if (scopeDetail.IsOpenIdScope) { ContainsOpenIdScopes = true; } else { ContainsResourceScopes = true; } GrantedScopes.Add(scopeDetail); } RequestedScopes.AddRange(GrantedScopes); return(true); }
/// <summary> /// Returns true if MsalAuthParameters instances are equal /// </summary> /// <param name="other">Instance of MsalAuthParameters to be compared</param> /// <returns>Boolean</returns> public bool Equals(MsalAuthParameters other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return ((ClientApplicationId == other.ClientApplicationId || ClientApplicationId != null && ClientApplicationId.Equals(other.ClientApplicationId)) && (ClientId == other.ClientId || ClientId != null && ClientId.Equals(other.ClientId)) && (Authority == other.Authority || Authority != null && Authority.Equals(other.Authority)) && (RedirectUri == other.RedirectUri || RedirectUri != null && RedirectUri.Equals(other.RedirectUri)) && (RequestedScopes == other.RequestedScopes || RequestedScopes != null && RequestedScopes.Equals(other.RequestedScopes)) && (Username == other.Username || Username != null && Username.Equals(other.Username)) && (Password == other.Password || Password != null && Password.Equals(other.Password)) && (TelemetryCorrelationId == other.TelemetryCorrelationId || TelemetryCorrelationId != null && TelemetryCorrelationId.Equals(other.TelemetryCorrelationId)) && (AuthorizationType == other.AuthorizationType || AuthorizationType != null && AuthorizationType.Equals(other.AuthorizationType))); }
/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { unchecked // Overflow is fine, just wrap { int hashCode = 41; // Suitable nullity checks etc, of course :) if (ClientApplicationId != null) { hashCode = hashCode * 59 + ClientApplicationId.GetHashCode(); } if (ClientId != null) { hashCode = hashCode * 59 + ClientId.GetHashCode(); } if (Authority != null) { hashCode = hashCode * 59 + Authority.GetHashCode(); } if (RedirectUri != null) { hashCode = hashCode * 59 + RedirectUri.GetHashCode(); } if (RequestedScopes != null) { hashCode = hashCode * 59 + RequestedScopes.GetHashCode(); } if (Username != null) { hashCode = hashCode * 59 + Username.GetHashCode(); } if (Password != null) { hashCode = hashCode * 59 + Password.GetHashCode(); } if (TelemetryCorrelationId != null) { hashCode = hashCode * 59 + TelemetryCorrelationId.GetHashCode(); } if (AuthorizationType != null) { hashCode = hashCode * 59 + AuthorizationType.GetHashCode(); } return(hashCode); } }
public async Task <bool> AreScopesValidAsync(IEnumerable <string> requestedScopes) { var requestedScopesArray = requestedScopes as string[] ?? requestedScopes.ToArray(); var availableScopesArray = (await _store.FindEnabledScopesAsync(requestedScopesArray)).ToArray(); foreach (var requestedScope in requestedScopesArray) { var scopeDetail = availableScopesArray.FirstOrDefault(s => s.Name == requestedScope); if (scopeDetail == null) { _logger.LogError("Invalid scope: {requestedScope}", requestedScope); return(false); } if (scopeDetail.Enabled == false) { _logger.LogError("Scope disabled: {requestedScope}", requestedScope); return(false); } if (scopeDetail.Type == ScopeType.Identity) { ContainsOpenIdScopes = true; } else { ContainsResourceScopes = true; } GrantedScopes.Add(scopeDetail); } if (requestedScopesArray.Contains(Constants.StandardScopes.OfflineAccess)) { ContainsOfflineAccessScope = true; } RequestedScopes.AddRange(GrantedScopes); return(true); }
/// <summary>Request information about the authorization token.</summary> /// <returns>An object containing the returned information, or null if the request failed</returns> public TokenVerification VerifyToken() { while (VerifyCredentials()) { string Token; if (AuthToken != null && GrantType == OAuthGrant.Authorization) { Token = AuthToken.AccessToken; } else if (ImplicitToken != null && GrantType == OAuthGrant.Implicit) { Token = ImplicitToken.AccessToken; } else { return(null); } var VerificationClient = new HttpClient(); VerificationClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Token); VerificationClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var Response = VerificationClient.GetAsync("https://login.eveonline.com/oauth/verify").Result; if (Response.StatusCode != System.Net.HttpStatusCode.OK) { return(null); } var Json = Response.Content.ReadAsStringAsync().Result; var Result = JsonConvert.DeserializeObject <TokenVerification>(Json); if (!RequestedScopes.Contains(Scope.None) && !RequestedScopes.TrueForAll(x => Result.Scopes.Contains(x))) { ReauthorizeScopes = true; } else { return(Result); } } return(null); }
public bool AreScopesValid(IEnumerable <string> requestedScopes, IEnumerable <Scope> availableScopes) { foreach (var requestedScope in requestedScopes) { var scopeDetail = availableScopes.FirstOrDefault(s => s.Name == requestedScope); if (scopeDetail == null) { Logger.ErrorFormat("Invalid scope: {0}", requestedScope); return(false); } if (scopeDetail.Enabled == false) { Logger.ErrorFormat("Scope disabled: {0}", requestedScope); return(false); } if (scopeDetail.Type == ScopeType.Identity) { ContainsOpenIdScopes = true; } else { ContainsResourceScopes = true; } GrantedScopes.Add(scopeDetail); } if (requestedScopes.Contains(Constants.StandardScopes.OfflineAccess)) { ContainsOfflineAccessScope = true; } RequestedScopes.AddRange(GrantedScopes); return(true); }
public bool ValidateRequiredScopes(IEnumerable <string> consentedScopes) { var requiredScopes = RequestedScopes.Where(x => x.Required).Select(x => x.Name); return(requiredScopes.All(x => consentedScopes.Contains(x))); }