-
-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/add auth #44
Merged
Merged
Feature/add auth #44
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
30c34a9
Add user api
idormenco 94e5418
Merge branch 'develop' into feature/add-user-api
idormenco 69ed26d
Add auth with jwt and identity token
idormenco f162a88
Merge branch 'develop' into feature/add-auth
idormenco f08cf8a
Undo changes regenerate create
idormenco 4fc82b1
Undo changes
idormenco File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
Src/DeUrgenta.Api/Extensions/AuthorizeCheckOperationFilter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.OpenApi.Models; | ||
using Swashbuckle.AspNetCore.SwaggerGen; | ||
|
||
namespace DeUrgenta.Api.Extensions | ||
{ | ||
public class AuthorizeCheckOperationFilter : IOperationFilter | ||
{ | ||
public void Apply(OpenApiOperation operation, OperationFilterContext context) | ||
{ | ||
var attributes = context.MethodInfo.DeclaringType.GetCustomAttributes(true) | ||
.Union(context.MethodInfo.GetCustomAttributes(true)); | ||
|
||
if (attributes.OfType<IAllowAnonymous>().Any()) | ||
{ | ||
return; | ||
} | ||
|
||
var authAttributes = attributes.OfType<IAuthorizeData>(); | ||
|
||
if (authAttributes.Any()) | ||
{ | ||
operation.Responses["401"] = new OpenApiResponse { Description = "Unauthorized" }; | ||
|
||
if (authAttributes.Any(att => !String.IsNullOrWhiteSpace(att.Roles) || !String.IsNullOrWhiteSpace(att.Policy))) | ||
{ | ||
operation.Responses["403"] = new OpenApiResponse { Description = "Forbidden" }; | ||
} | ||
|
||
operation.Security = new List<OpenApiSecurityRequirement> | ||
{ | ||
new OpenApiSecurityRequirement | ||
{ | ||
{ | ||
new OpenApiSecurityScheme | ||
{ | ||
Reference = new OpenApiReference | ||
{ | ||
Id = "BearerAuth", | ||
Type = ReferenceType.SecurityScheme | ||
} | ||
}, | ||
Array.Empty<string>() | ||
} | ||
} | ||
}; | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,18 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft": "Warning", | ||
"Microsoft.Hosting.Lifetime": "Information" | ||
} | ||
}, | ||
"AllowedHosts": "*", | ||
"ConnectionStrings": { | ||
"DbConnectionString": "Server=localhost;Port=5432;Database=de-urgenta-db;User Id=docker;Password=docker;" | ||
}, | ||
"SwaggerOidcClientName": "swaggerClientLocalhost", | ||
"ApiConfiguration": [ | ||
{ | ||
"SchemeName": "backpackApiAuthenticationScheme", | ||
"ApiName": "backpackApi", | ||
"ApiSecret": "svpqYnJSR8xzn8Rl" | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft": "Warning", | ||
"Microsoft.Hosting.Lifetime": "Information" | ||
} | ||
}, | ||
{ | ||
"SchemeName": "usersApiAuthenticationScheme", | ||
"ApiName": "usersApi", | ||
"ApiSecret": "st4k!b7s$af201cv" | ||
"AllowedHosts": "*", | ||
"ConnectionStrings": { | ||
"DbConnectionString": "Server=localhost;Port=5432;Database=de-urgenta-db;User Id=docker;Password=docker;", | ||
"IdentityDbConnectionString": "Server=localhost;Port=5432;Database=de-urgenta-db;User Id=docker;Password=docker;" | ||
}, | ||
{ | ||
"SchemeName": "certificationsApiAuthenticationScheme", | ||
"ApiName": "certificationsApi", | ||
"ApiSecret": "Mfrf5DIry96z851k" | ||
"JwtConfig": { | ||
"Secret": "llvudfvkwvepwkdnsnwmuulyvtrawppf", | ||
"TokenExpirationInSeconds": 3600 | ||
} | ||
], | ||
"IdentityServerUrl": "https://localhost:5001" | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eu aici in readme as pune si cum sa rulam database update
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@trupci do we need this ? because we call Migrate database when adding db context