Skip to content
This repository has been archived by the owner on Dec 18, 2023. It is now read-only.

Commit

Permalink
Remove authentication type
Browse files Browse the repository at this point in the history
  • Loading branch information
ProphetLamb committed Sep 27, 2022
1 parent 17f196d commit b069ec9
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 34 deletions.
8 changes: 4 additions & 4 deletions src/Abstractions/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public interface IDatabase<TResponse>
/// Signs up to a specific authentication scope.
/// </summary>
/// <param name="auth"> Variables used in a signin query. </param>
public new Task<TResponse> Signup(Authentication auth, CancellationToken ct = default);
public new Task<TResponse> Signup(object auth, CancellationToken ct = default);

/// <summary>
/// Signs in to a specific authentication scope.
Expand All @@ -36,7 +36,7 @@ public interface IDatabase<TResponse>
/// <remarks>
/// This updates the internal <see cref="Config" />.
/// </remarks>
public new Task<TResponse> Signin(Authentication auth, CancellationToken ct = default);
public new Task<TResponse> Signin(object auth, CancellationToken ct = default);

/// <summary>
/// Invalidates the authentication for the current connection.
Expand Down Expand Up @@ -180,7 +180,7 @@ public interface IDatabase {
/// Signs up to a specific authentication scope.
/// </summary>
/// <param name="auth"> Variables used in a signin query. </param>
public Task<IResponse> Signup(Authentication auth, CancellationToken ct = default);
public Task<IResponse> Signup(object auth, CancellationToken ct = default);

/// <summary>
/// Signs in to a specific authentication scope.
Expand All @@ -189,7 +189,7 @@ public interface IDatabase {
/// <remarks>
/// This updates the internal <see cref="Config" />.
/// </remarks>
public Task<IResponse> Signin(Authentication auth, CancellationToken ct = default);
public Task<IResponse> Signin(object auth, CancellationToken ct = default);

/// <summary>
/// Invalidates the authentication for the current connection.
Expand Down
2 changes: 1 addition & 1 deletion src/Configuration/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,4 @@ public void ThrowIfInvalid() {
throw new InvalidConfigException("The configuration is not marked as valid.");
}
}
}
}
2 changes: 1 addition & 1 deletion src/Configuration/ConfigBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -373,4 +373,4 @@ public static Uri GetUri(
: new Uri($"https://{endPoint}/");
}
}
}
}
6 changes: 3 additions & 3 deletions src/Driver/Rest/DatabaseRest.IDatabase.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using SurrealDB.Abstractions;
using SurrealDB.Models;

namespace SurrealDB.Driver.Rest;
namespace SurrealDB.Driver.Rest;

public sealed partial class DatabaseRest : IDatabase {
async Task<IResponse> IDatabase.Info(CancellationToken ct) {
Expand All @@ -12,11 +12,11 @@ async Task<IResponse> IDatabase.Use(string db, string ns, CancellationToken ct)
return await Use(db, ns, ct);
}

async Task<IResponse> IDatabase.Signup(Authentication auth, CancellationToken ct) {
async Task<IResponse> IDatabase.Signup(object auth, CancellationToken ct) {
return await Signup(auth, ct);
}

async Task<IResponse> IDatabase.Signin(Authentication auth, CancellationToken ct) {
async Task<IResponse> IDatabase.Signin(object auth, CancellationToken ct) {
return await Signin(auth, ct);
}

Expand Down
6 changes: 3 additions & 3 deletions src/Driver/Rest/DatabaseRest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ public Task<RestResponse> Use(
}

public async Task<RestResponse> Signup(
Authentication auth,
object auth,
CancellationToken ct = default) {
return await Signup(ToJsonContent(auth), ct);
}

public async Task<RestResponse> Signin(
Authentication auth,
object auth,
CancellationToken ct = default) {
SetAuth(auth.Username, auth.Password);
// SetAuth(auth.Username, auth.Password);
HttpResponseMessage rsp = await _client.PostAsync("signin", ToJsonContent(auth), ct);
return await rsp.ToSurreal();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Driver/Rpc/DatabaseRpc.IDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ async Task<IResponse> IDatabase.Use(string db, string ns, CancellationToken ct)
return await Use(db, ns, ct);
}

async Task<IResponse> IDatabase.Signup(Authentication auth, CancellationToken ct) {
async Task<IResponse> IDatabase.Signup(object auth, CancellationToken ct) {
return await Signup(auth, ct);
}

async Task<IResponse> IDatabase.Signin(Authentication auth, CancellationToken ct) {
async Task<IResponse> IDatabase.Signin(object auth, CancellationToken ct) {
return await Signin(auth, ct);
}

Expand Down
6 changes: 3 additions & 3 deletions src/Driver/Rpc/DatabaseRpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ public async Task<RpcResponse> Use(

/// <inheritdoc />
public async Task<RpcResponse> Signup(
Authentication auth,
object auth,
CancellationToken ct = default) {
return await _client.Send(new() { method = "signup", parameters = new() { auth, }, }, ct).ToSurreal();
}

/// <inheritdoc />
public async Task<RpcResponse> Signin(
Authentication auth,
object auth,
CancellationToken ct = default) {
WsClient.Response rsp = await _client.Send(new() { method = "signin", parameters = new() { auth, }, }, ct);

Expand Down Expand Up @@ -184,7 +184,7 @@ private async Task SetAuth(
// TODO: Support jwt auth
_config.Username = user;
_config.Password = pass;
await Signin(new() { Username = user, Password = pass, }, ct);
await Signin(new{ user = user, pass = pass, }, ct);
}

public void Dispose() {
Expand Down
16 changes: 0 additions & 16 deletions src/Models/Authentication.cs

This file was deleted.

2 changes: 1 addition & 1 deletion tests/Driver.Tests/DatabaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected override async Task Run(T db) {
IResponse infoResp = await db.Info();
AssertOk(infoResp);

IResponse signInStatus = await db.Signin(new() { Username = TestHelper.User, Password = TestHelper.Pass, });
IResponse signInStatus = await db.Signin(new{ user = TestHelper.User, pass = TestHelper.Pass, });

AssertOk(signInStatus);
//AssertOk(await db.Invalidate());
Expand Down

0 comments on commit b069ec9

Please sign in to comment.