You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
>**Note:** If you don't inform the configuration name the value adopted will be _AppJwtSettings_
80
80
81
-
82
81
Set your `appsettings.json` file with this values:
83
82
84
83
```json
85
-
"AppSettings": {
86
-
"SecretKey": "MYSECRETSUPERSECRET",
87
-
"Expiration": 2,
88
-
"Issuer": "SampleApp",
89
-
"Audience": "https://localhost"
84
+
"AppJwtSettings": {
85
+
"Expiration": 1,
86
+
"Issuer": "https://my-application.com",
87
+
"Audience": "MyApplication.Name"
90
88
}
91
89
```
92
90
93
-
|Key|Meaning|
94
-
|--|--|
95
-
|SecretKey | Is your key to build JWT. This value need to be stored in a safe place in the production way |
96
-
|Expiration| Expiration time in hours |
97
-
|Issuer| The name of the JWT issuer |
98
-
|Audience| The domain that the JWT will be valid. Can be a string collection |
91
+
|Key|Meaning|Default
92
+
|--|--|---|
93
+
|Expiration| Expiration time (in hours) | 1 |
94
+
|Issuer| The name of the JWT issuer | NetDevPack.Identity |
95
+
|Audience| The domain that the JWT will be valid | Api |
96
+
|RefreshTokenExpiration | Refresh token expiration (In Days) | 30 |
97
+
|SecretKey `Deprecated`| Is your key to build JWT. **Read notes**| Do not use it |
98
+
99
+
>**Note:** Now we are using [NetDevPack.Security.Jwt](https://github.com/NetDevPack/Security.Jwt) to generate and Store your keys. It generate a RSA 2048 by default. You can check the project for more info.
99
100
100
101
### Generating JWT
101
-
You will need to set some dependencies in your Authentication Controller:
102
+
You will need to set a single dependency in your Authentication Controller:
>**Note:** The _AppJwtSettings_ is our dependency and is configured internally during JWT setup (in `startup.cs` file). You just need to inject it in your controller.
119
-
>
120
-
>**Note:** The _SignInManager_ and _UserManager_ classes is native from Identity and provided in NetDevPack.Identity. You just need to inject it in your controller.
121
-
122
112
After user register or login process you can generate a JWT to respond the request. Use our implementation, you just need inform the user email and the dependencies injected in your controller:
123
113
124
114
```csharp
125
-
returnnewJwtBuilder()
126
-
.WithUserManager(_userManager)
127
-
.WithJwtSettings(_appJwtSettings)
115
+
return_jwtBuilder
128
116
.WithEmail(email)
117
+
.WithRefreshToken()
129
118
.BuildToken();
130
119
```
131
120
@@ -135,13 +124,12 @@ return new JwtBuilder()
135
124
You can call more methods in `JwtBuilder` to provide more information about the user:
136
125
137
126
```csharp
138
-
returnnewJwtBuilder()
139
-
.WithUserManager(_userManager)
140
-
.WithJwtSettings(_appJwtSettings)
127
+
return_jwtBuilder
141
128
.WithEmail(email)
142
129
.WithJwtClaims()
143
130
.WithUserClaims()
144
131
.WithUserRoles()
132
+
.WithRefreshToken()
145
133
.BuildToken();
146
134
```
147
135
@@ -155,23 +143,20 @@ return new JwtBuilder()
155
143
If you want return your complex object `UserResponse` you need to change the last method to:
156
144
157
145
```csharp
158
-
returnnewJwtBuilder()
159
-
.WithUserManager(_userManager)
160
-
.WithJwtSettings(_appJwtSettings)
146
+
return_jwtBuilder
161
147
.WithEmail(email)
162
148
.WithJwtClaims()
163
149
.WithUserClaims()
164
150
.WithUserRoles()
165
-
.BuildUserResponse() asUserResponse;
151
+
.WithRefreshToken()
152
+
.BuildUserResponse();
166
153
```
167
154
168
-
>**Note:** The safe cast to `UserResponse` is needed because is a subtype of `UserResponse<TKey>`.
169
-
170
155
## Examples
171
156
Use the [sample application](https://github.com/NetDevPack/NetDevPack.Identity/tree/master/src/Samples/AspNetCore.Jwt.Sample) to understand how NetDevPack.Identity can be implemented and help you to decrease the complexity of your application and development time.
172
157
173
158
## Compatibility
174
-
The **NetDevPack.Identity** was developed to be implemented in **ASP.NET Core 3.1**`LTS` applications, in the next versions will be add the 2.1 `LTS` support.
159
+
The **NetDevPack.Identity** was developed to be implemented in **ASP.NET Core**. It support all .NET versions since 3.1.
175
160
176
161
## About
177
162
.NET DevPack.Identity was developed by [Eduardo Pires](http://eduardopires.net.br) under the [MIT license](LICENSE).
0 commit comments