Skip to content

Commit

Permalink
Merge pull request #63 from fossapps/federation
Browse files Browse the repository at this point in the history
Federation
  • Loading branch information
cyberhck authored Jul 4, 2021
2 parents c330738 + ec5cef7 commit c039433
Show file tree
Hide file tree
Showing 34 changed files with 217 additions and 494 deletions.

This file was deleted.

150 changes: 0 additions & 150 deletions Micro.Auth.Api/Authentication/SessionController.cs

This file was deleted.

This file was deleted.

5 changes: 3 additions & 2 deletions Micro.Auth.Api/GraphQL/AuthSchema.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System;
using Micro.Auth.Api.GraphQL.Federation;
using Micro.Auth.Api.GraphQL.Types;
using Micro.GraphQL.Federation;
using Micro.Auth.Api.GraphQL.Directives;

namespace Micro.Auth.Api.GraphQL
{
public class AuthSchema : Schema
public class AuthSchema : Schema<EntityType>
{
public AuthSchema(IServiceProvider services, Query query, Mutation mutation) : base(services)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace Micro.Auth.Api.GraphQL.Extensions.Exceptions
{
public class InvalidTokenTypeException : Exception
{
public InvalidTokenTypeException(string expectedType) : base($"{expectedType} token not found")
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace Micro.Auth.Api.GraphQL.Extensions.Exceptions
{
public class MissingHeaderException : Exception
{
public MissingHeaderException(string headerName) : base($"Missing {headerName} header")
{
}
}
}
22 changes: 22 additions & 0 deletions Micro.Auth.Api/GraphQL/Extensions/LoginRequestExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Micro.Auth.Api.Internal.UserData.Extensions;
using Micro.Auth.Business.Sessions;
using Microsoft.AspNetCore.Http;

namespace Micro.Auth.Api.GraphQL.Extensions
{
public static class LoginRequestExtension
{
public static LoginRequest GetLoginRequest(this IHttpContextAccessor httpContextAccessor)
{
var (login, password) = httpContextAccessor.MustGetBasicToken();
return new LoginRequest
{
Login = login,
Password = password,
IpAddress = httpContextAccessor.GetIpAddress(),
UserAgent = httpContextAccessor.GetUserAgent(),
Location = httpContextAccessor.GetRoughLocation()
};
}
}
}
53 changes: 53 additions & 0 deletions Micro.Auth.Api/GraphQL/Extensions/Tokens.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System;
using System.Text;
using Micro.Auth.Api.GraphQL.Extensions.Exceptions;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Primitives;

namespace Micro.Auth.Api.GraphQL.Extensions
{
public static class Tokens
{
public static string MustGetBearerToken(this IHttpContextAccessor httpContextAccessor)
{
var headerValue = httpContextAccessor.MustGetAuthHeader();
if (!headerValue.StartsWith("Bearer "))
{
throw new InvalidTokenTypeException("Bearer");
}
return headerValue.Substring("Bearer ".Length).Trim();
}

private static string MustGetAuthHeader(this IHttpContextAccessor httpContextAccessor)
{
var header = StringValues.Empty;
var exists = httpContextAccessor.HttpContext?.Request.Headers.TryGetValue("Authorization", out header);
if (exists == false || header.ToString() == "")
{
throw new MissingHeaderException("Authorization");
}

return header.ToString();
}

public static (string, string) MustGetBasicToken(this IHttpContextAccessor httpContextAccessor)
{
try
{
var headerValue = httpContextAccessor.MustGetAuthHeader();
if (!headerValue.StartsWith("Basic "))
{
throw new InvalidTokenTypeException("Basic");
}

var token = headerValue.Substring("Basic ".Length).Trim();
var parts = Encoding.UTF8.GetString(Convert.FromBase64String(token)).Split(":");
return (parts[0], parts[1]);
}
catch (Exception e)
{
throw new InvalidTokenTypeException(e.Message);
}
}
}
}
15 changes: 0 additions & 15 deletions Micro.Auth.Api/GraphQL/Federation/EntityType.cs

This file was deleted.

14 changes: 0 additions & 14 deletions Micro.Auth.Api/GraphQL/Federation/ExtendsDirective.cs

This file was deleted.

57 changes: 0 additions & 57 deletions Micro.Auth.Api/GraphQL/Federation/Extensions.cs

This file was deleted.

15 changes: 0 additions & 15 deletions Micro.Auth.Api/GraphQL/Federation/ExternalDirective.cs

This file was deleted.

Loading

0 comments on commit c039433

Please sign in to comment.