public OAuthClient GetOAuthClientByKey(String clientApiKey) { Guid clientKeyGuid = Guid.Empty; Guid.TryParse(clientApiKey, out clientKeyGuid); Client client = new Client(clientKeyGuid); return (new OAuthClientMapper()).FromArena(client); }
public ModifyResult UpdateOAuthUserAuthorization(String clientApiKey, OAuthAuthorization auth) { Arena.Custom.SECC.OAuth.Client client = new Arena.Custom.SECC.OAuth.Client(new Guid(clientApiKey)); if (auth.ClientId != client.ClientId) { throw new ResourceNotFoundException("Client API Key mismatch."); } // Create the mapper Arena.Custom.HDC.WebService.Contracts.OAuthAuthorizationMapper mapper = new Arena.Custom.HDC.WebService.Contracts.OAuthAuthorizationMapper(); if (auth.AuthorizationId > 0) { return(mapper.Update(auth)); } else { return(mapper.Create(auth)); } }
public OAuthClient getOAuthClientById(int id) { Client client = new Client(id); return (new OAuthClientMapper()).FromArena(client); }
public ModifyResult UpdateOAuthUserAuthorization(String clientApiKey, OAuthAuthorization auth) { Arena.Custom.SECC.OAuth.Client client = new Arena.Custom.SECC.OAuth.Client(new Guid(clientApiKey)); if (auth.ClientId != client.ClientId) { throw new ResourceNotFoundException("Client API Key mismatch."); } // Create the mapper Arena.Custom.HDC.WebService.Contracts.OAuthAuthorizationMapper mapper = new Arena.Custom.HDC.WebService.Contracts.OAuthAuthorizationMapper(); if (auth.AuthorizationId > 0) { return mapper.Update(auth); } else { return mapper.Create(auth); } }
public OAuthClient OAuthClientValidate(String clientApiKey, String clientApiSecret) { Guid clientKeyGuid = Guid.Empty; Guid clientProvidedSecret = Guid.Empty; Guid.TryParse(clientApiKey, out clientKeyGuid); Guid.TryParse( clientApiSecret, out clientProvidedSecret ); Client client = new Client(clientKeyGuid); if (client.ApiSecret != null && client.ApiSecret.Equals(clientProvidedSecret)) { OAuthClientMapper mapper = new OAuthClientMapper(); return mapper.FromArena(client); } throw new RESTException(new Exception("Invalid API Credentials"), System.Net.HttpStatusCode.Forbidden, "Invalid API Key/Secret Combination."); }
public OAuthClient FromArena(Client dbClient) { OAuthClient client = new OAuthClient(); client.ClientID = dbClient.ClientId; client.APIKey = dbClient.ApiKey.ToString(); client.Active = dbClient.Active; client.CallbackURL = dbClient.Callback; client.Name = dbClient.Name; client.Scopes = new List<OAuthScope>(); foreach(Scope dbScope in dbClient.Scopes) { OAuthScope scope = new OAuthScope(); scope.Active = dbScope.Active; scope.Description = dbScope.Description; scope.Identifier = dbScope.Identifier; scope.ScopeID = dbScope.ScopeId; client.Scopes.Add(scope); } return client; }
private void Init() { AuthorizationId = 0; ClientId = 0; ScopeId = 0; LoginId = null; DateCreated = DateTime.MinValue; Active = false; mClient = null; mScope = null; mUser = null; }
public static void AuthorizeScopes( string loginId, string clientKey, string[] scopes ) { Guid clientKeyGuid; if ( !Guid.TryParse( clientKey, out clientKeyGuid ) ) { throw new ArgumentException( "Client Key/ID is not valid", "clientKey" ); } Client c = new Client( clientKeyGuid ); if ( c.ClientId <= 0 ) { throw new ArgumentException( "Client Key/ID is not valid.", "clientKey" ); } foreach ( var scope in scopes ) { using ( OAuthDataContext context = OAuthContextHelper.GetContext() ) { bool isExistingAuth = context.AuthorizationDatas .Where( a => a.client_id == c.ClientId ) .Where( a => a.login_id.ToLower() == loginId.ToLower()) .Where( a => a.ScopeData.scope_identifier.ToLower() == scope.ToLower()) .Where(a => a.active) .Count() > 0; bool isClientScope = c.Scopes.Where( s => s.Identifier.ToLower() == scope.ToLower()) .Where( s => s.Active ).Count() > 0; if ( isClientScope && !isExistingAuth ) { AddUserAuthorization( loginId, c.ClientId, new Scope(scope).ScopeId ); } else if ( !isClientScope ) { throw new ArgumentException( string.Format( "Scope {0} is not valid for client.", scope ), "scope" ); } } } }