Skip to content

Commit 3f82a6f

Browse files
committed
Release 2.0.
1 parent f19f3f3 commit 3f82a6f

7 files changed

+27
-97
lines changed

CHANGELOG.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
This is the changelog for [Authress SDK](readme.md).
33

44
## 2.0 ##
5-
* Renamed `AccessRecordStatements` and other models that end with `S` but aren't actually plural to be `AccessRecordStatement` (without the `S`).
6-
* All APIs are now part of sub instance properties of the `AuthressClient` class, `AccessClient.AccessRecords` and `AccessClient.ServiceClients`, etc..
75
* `ApiBasePath` has been renamed to `AuthressApiUrl`.
86
* `HttpClientSettings` Has been removed in favor of `AuthressSettings` Class.
7+
* [Breaking] `UserPermissions.GetUserResources()` no longer returns the property `AccessToAllSubResources`. When a user only has access to parent resources, the list will always be empty unless the `CollectionConfigurationEnum` property is specified.
98

109
## 1.5 ##
1110
* Fix `DateTimeOffset` type assignments, properties that were incorrectly defined as `DateTime` are now correctly `DateTimeOffsets`.

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ The recommended solution is to use the C# built in OpenID provider by Microsoft.
3131
using Authress.SDK;
3232

3333
// Get an authress custom domain: https://authress.io/app/#/settings?focus=domain
34-
var authressSettings = new AuthressSettings { ApiBasePath = "https://authress.company.com", };
34+
var authressSettings = new AuthressSettings { AuthressApiUrl = "https://authress.company.com", };
3535
var authressClient = new AuthressClient(tokenProvider, authressSettings)
3636

3737
var verifiedUserIdentity = await authressClient.VerifyToken(jwtToken);
@@ -60,7 +60,7 @@ namespace Microservice
6060
return accessToken;
6161
});
6262
// Get an authress custom domain: https://authress.io/app/#/settings?focus=domain
63-
var authressSettings = new AuthressSettings { ApiBasePath = "https://authress.company.com", };
63+
var authressSettings = new AuthressSettings { AuthressApiUrl = "https://authress.company.com", };
6464
var authressClient = new AuthressClient(tokenProvider, authressSettings);
6565

6666
// 2. At runtime attempt to Authorize the user for the resource
@@ -86,7 +86,7 @@ namespace Microservice
8686
// automatically populate forward the users token
8787
// 1. instantiate all the necessary classes
8888
var tokenProvider = new ManualTokenProvider();
89-
var authressSettings = new AuthressSettings { ApiBasePath = "https://DOMAIN.api.authress.io", };
89+
var authressSettings = new AuthressSettings { AuthressApiUrl = "https://DOMAIN.api.authress.io", };
9090
var authressClient = new AuthressClient(tokenProvider, authressSettings);
9191

9292
// 2. At runtime attempt to Authorize the user for the resource
@@ -117,7 +117,7 @@ namespace Microservice
117117
var decodedAccessKey = decrypt(accessKey);
118118
var tokenProvider = new AuthressClientTokenProvider(decodedAccessKey);
119119
// Get an authress custom domain: https://authress.io/app/#/settings?focus=domain
120-
var authressSettings = new AuthressSettings { ApiBasePath = "https://authress.company.com", };
120+
var authressSettings = new AuthressSettings { AuthressApiUrl = "https://authress.company.com", };
121121
var authressClient = new AuthressClient(tokenProvider, authressSettings);
122122

123123
// Attempt to Authorize the user for the resource

src/Authress.SDK/Api/IUserPermissionsApi.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Authress.SDK.Api
1111
public interface IUserPermissionsApi
1212
{
1313
/// <summary>
14-
/// Get the users resources. Get the users resources. This result is a list of resource uris that a user has an explicit permission to, a user with * access to all sub resources will return an empty list and {AccessToAllSubResources} will be populated. The list will be paginated.
14+
/// Get the users resources. This result is a list of resource uris that a user has an permission to. By default only the top level matching resources are returned. To get a user's list of deeply nested resources, set the collectionConfiguration to be INCLUDE_NESTED. This collection is paginated.
1515
/// </summary>
1616
/// <param name="userId">The user to check permissions on</param>
1717
/// <param name="resourceCollectionUri">The uri path of a collection resource to fetch permissions for.</param>

src/Authress.SDK/Api/UserPermissionsApi.cs

+13-47
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public async Task AuthorizeUser (string userId, string resourceUri, string permi
135135
}
136136

137137
/// <summary>
138-
/// Get the users resources. Get the users resources. This result is a list of resource uris that a user has an explicit permission to, a user with * access to all sub resources will return an empty list and {AccessToAllSubResources} will be populated. The list will be paginated.
138+
/// Get the users resources. This result is a list of resource uris that a user has an permission to. By default only the top level matching resources are returned. To get a user's list of deeply nested resources, set the collectionConfiguration to be INCLUDE_NESTED. This collection is paginated.
139139
/// </summary>
140140
/// <param name="userId">The user to check permissions on</param>
141141
/// <param name="resourceCollectionUri">The uri path of a collection resource to fetch permissions for.</param>
@@ -152,56 +152,22 @@ public async Task<UserResources> GetUserResources(string userId, string resource
152152
throw new ArgumentNullException("Missing required parameter 'userId'.");
153153
}
154154

155-
if (collectionConfiguration == CollectionConfigurationEnum.INCLUDE_NESTED)
155+
var queryParams = new Dictionary<string, string>
156156
{
157-
var queryParams = new Dictionary<string, string>
158-
{
159-
{ "resourceUri", resourceCollectionUri },
160-
{ "permissions", permission },
161-
{ "collectionConfiguration", collectionConfiguration.ToString() }
162-
};
157+
{ "resourceUri", resourceCollectionUri },
158+
{ "permissions", permission },
159+
{ "collectionConfiguration", collectionConfiguration.ToString() }
160+
};
163161

164-
var queryString = queryParams.Where(pair => !string.IsNullOrEmpty(pair.Value))
165-
.Select(pair => $"{pair.Key}={System.Web.HttpUtility.UrlEncode(pair.Value)}").Aggregate((next, total) => $"{total}&{next}");
166-
var path = $"/v1/users/{System.Web.HttpUtility.UrlEncode(userId)}/resources?{queryString}";
162+
var queryString = queryParams.Where(pair => !string.IsNullOrEmpty(pair.Value))
163+
.Select(pair => $"{pair.Key}={System.Web.HttpUtility.UrlEncode(pair.Value)}").Aggregate((next, total) => $"{total}&{next}");
164+
var path = $"/v1/users/{System.Web.HttpUtility.UrlEncode(userId)}/resources?{queryString}";
167165

168-
var client = await authressHttpClientProvider.GetHttpClientAsync();
169-
using (var response = await client.GetAsync(path))
170-
{
171-
await response.ThrowIfNotSuccessStatusCode();
172-
return await response.Content.ReadAsAsync<UserResources>();
173-
}
174-
}
175-
else
166+
var client = await authressHttpClientProvider.GetHttpClientAsync();
167+
using (var response = await client.GetAsync(path))
176168
{
177-
178-
var queryParams = new Dictionary<string, string>
179-
{
180-
{ "resourceUri", resourceCollectionUri },
181-
{ "permissions", permission }
182-
};
183-
184-
var queryString = queryParams.Where(pair => !string.IsNullOrEmpty(pair.Value))
185-
.Select(pair => $"{pair.Key}={System.Web.HttpUtility.UrlEncode(pair.Value)}").Aggregate((next, total) => $"{total}&{next}");
186-
var path = $"/v1/users/{System.Web.HttpUtility.UrlEncode(userId)}/resources?{queryString}";
187-
188-
var client = await authressHttpClientProvider.GetHttpClientAsync();
189-
190-
var authorizeUserAsync = AuthorizeUser(userId, resourceCollectionUri, permission);
191-
using (var response = await client.GetAsync(path))
192-
{
193-
try
194-
{
195-
await authorizeUserAsync;
196-
return new UserResources { UserId = userId, AccessToAllSubResources = true, Resources = null };
197-
}
198-
catch (Exception)
199-
{
200-
/* Ignore if the user doesn't have permission or if there is a problem, instead fallback to looking up explicit resources by permission */
201-
}
202-
await response.ThrowIfNotSuccessStatusCode();
203-
return await response.Content.ReadAsAsync<UserResources>();
204-
}
169+
await response.ThrowIfNotSuccessStatusCode();
170+
return await response.Content.ReadAsAsync<UserResources>();
205171
}
206172
}
207173
}

src/Authress.SDK/Client/AuthressClient.cs

+1-15
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,7 @@ public AuthressClient(ITokenProvider tokenProvider, AuthressSettings settings, I
2828
throw new ArgumentNullException("Missing required parameter AuthressSettings");
2929
}
3030
authressHttpClientProvider = new HttpClientProvider(settings, tokenProvider, customHttpClientHandlerFactory);
31-
tokenVerifier = new TokenVerifier(settings.ApiBasePath, authressHttpClientProvider);
32-
}
33-
34-
/// <summary>
35-
/// Deprecated Constructor
36-
/// </summary>
37-
public AuthressClient(ITokenProvider tokenProvider, HttpClientSettings settings, IHttpClientHandlerFactory customHttpClientHandlerFactory = null)
38-
{
39-
if (settings == null) {
40-
throw new ArgumentNullException("Missing required parameter HttpClientSettings");
41-
}
42-
authressHttpClientProvider = new HttpClientProvider(
43-
new AuthressSettings { ApiBasePath = settings.ApiBasePath, RequestTimeout = settings.RequestTimeout },
44-
tokenProvider, customHttpClientHandlerFactory);
45-
tokenVerifier = new TokenVerifier(settings.ApiBasePath, authressHttpClientProvider);
31+
tokenVerifier = new TokenVerifier(settings.AuthressApiUrl, authressHttpClientProvider);
4632
}
4733

4834
/// <summary>

src/Authress.SDK/Client/HttpClientProvider.cs

+7-23
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,19 @@ public interface IHttpClientHandlerFactory
1717
HttpClientHandler Create();
1818
}
1919

20-
/// <summary>
21-
/// Authress Domain Host: https://authress.company.com (Get an authress custom domain: https://authress.io/app/#/settings?focus=domain)
22-
/// </summary>
23-
public class HttpClientSettings
24-
{
25-
/// <summary>
26-
/// Authress Domain Host: https://authress.company.com (Get an authress custom domain: https://authress.io/app/#/settings?focus=domain)
27-
/// </summary>
28-
public string ApiBasePath { get; set; } = "https://api.authress.io";
29-
30-
/// <summary>
31-
/// Timeout for requests to Authress. Default is unset.
32-
/// </summary>
33-
public TimeSpan? RequestTimeout { get; set; } = null;
34-
}
35-
3620
/// <summary>
3721
/// Authress Domain Host: https://authress.company.com (Get an authress custom domain: https://authress.io/app/#/settings?focus=domain)
3822
/// </summary>
3923
public class AuthressSettings
4024
{
41-
private string apiBasePath = "https://api.authress.io";
25+
private string authressApiUrl = "https://api.authress.io";
4226
/// <summary>
4327
/// Authress Domain Host: https://authress.company.com (Get an authress custom domain: https://authress.io/app/#/settings?focus=domain)
4428
/// </summary>
45-
public string ApiBasePath {
46-
get { return apiBasePath; }
29+
public string AuthressApiUrl {
30+
get { return authressApiUrl; }
4731
set {
48-
apiBasePath = Sanitizers.SanitizeUrl(value);
32+
authressApiUrl = Sanitizers.SanitizeUrl(value);
4933
}
5034
}
5135

@@ -116,8 +100,8 @@ public async Task<HttpClient> GetHttpClientAsync()
116100

117101
// List of Handlers that never need to be retried
118102
outermostHandler = new OptimisticPerformanceHandler(outermostHandler, settings.CacheFallbackNormTimeout);
119-
outermostHandler = new RewriteBaseUrlHandler(outermostHandler, settings.ApiBasePath);
120-
outermostHandler = new AddAuthorizationHeaderHandler(outermostHandler, tokenProvider, settings.ApiBasePath);
103+
outermostHandler = new RewriteBaseUrlHandler(outermostHandler, settings.AuthressApiUrl);
104+
outermostHandler = new AddAuthorizationHeaderHandler(outermostHandler, tokenProvider, settings.AuthressApiUrl);
121105
outermostHandler = new AddUserAgentHeaderHandler(outermostHandler);
122106
/**** ⌃ Called First ⌃ ******/
123107

@@ -128,7 +112,7 @@ public async Task<HttpClient> GetHttpClientAsync()
128112
clientProxy.Timeout = settings.RequestTimeout.Value;
129113
}
130114

131-
clientProxy.BaseAddress = new Uri(settings.ApiBasePath);
115+
clientProxy.BaseAddress = new Uri(settings.AuthressApiUrl);
132116
return clientProxy;
133117
}
134118
finally

src/Authress.SDK/Model/UserResources.cs

-5
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,5 @@ public class UserResources : IPaginationDto
3434
[DataMember(Name = "links", EmitDefaultValue = false)]
3535
[JsonProperty(PropertyName = "links")]
3636
public Links Links { get; set; }
37-
38-
/// <summary>
39-
/// If the user has access to all sub-resources, then instead of resources being a list, this property will be populated `true`.
40-
/// </summary>
41-
public bool AccessToAllSubResources { get; set; } = false;
4237
}
4338
}

0 commit comments

Comments
 (0)