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
-
81
-
82
79
Set your `appsettings.json` file with this values:
83
80
84
81
```json
85
-
"AppSettings": {
86
-
"SecretKey": "MYSECRETSUPERSECRET",
87
-
"Expiration": 2,
88
-
"Issuer": "SampleApp",
89
-
"Audience": "https://localhost"
82
+
"AppJwtSettings": {
83
+
"Issuer": "https://my-application.com",
84
+
"Audience": "MyApplication.Name"
90
85
}
91
86
```
87
+
It's possible to configure some aspects of token
92
88
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 |
89
+
|Key|Meaning|Default
90
+
|--|--|---|
91
+
|Expiration| Expiration time (in hours) | 1 |
92
+
|Issuer| The name of the JWT issuer | NetDevPack.Identity |
93
+
|Audience| The domain that the JWT will be valid | Api |
94
+
|RefreshTokenExpiration | Refresh token expiration (In Days) | 30 |
95
+
|SecretKey `Deprecated`| Is your key to build JWT. **Read notes**| Do not use it |
96
+
97
+
>**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
98
100
99
### Generating JWT
101
-
You will need to set some dependencies in your Authentication Controller:
100
+
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
110
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
111
124
112
```csharp
125
-
returnnewJwtBuilder()
126
-
.WithUserManager(_userManager)
127
-
.WithJwtSettings(_appJwtSettings)
113
+
return_jwtBuilder
128
114
.WithEmail(email)
115
+
.WithRefreshToken()
129
116
.BuildToken();
130
117
```
131
118
@@ -135,13 +122,12 @@ return new JwtBuilder()
135
122
You can call more methods in `JwtBuilder` to provide more information about the user:
136
123
137
124
```csharp
138
-
returnnewJwtBuilder()
139
-
.WithUserManager(_userManager)
140
-
.WithJwtSettings(_appJwtSettings)
125
+
return_jwtBuilder
141
126
.WithEmail(email)
142
127
.WithJwtClaims()
143
128
.WithUserClaims()
144
129
.WithUserRoles()
130
+
.WithRefreshToken()
145
131
.BuildToken();
146
132
```
147
133
@@ -155,23 +141,20 @@ return new JwtBuilder()
155
141
If you want return your complex object `UserResponse` you need to change the last method to:
156
142
157
143
```csharp
158
-
returnnewJwtBuilder()
159
-
.WithUserManager(_userManager)
160
-
.WithJwtSettings(_appJwtSettings)
144
+
return_jwtBuilder
161
145
.WithEmail(email)
162
146
.WithJwtClaims()
163
147
.WithUserClaims()
164
148
.WithUserRoles()
165
-
.BuildUserResponse() asUserResponse;
149
+
.WithRefreshToken()
150
+
.BuildUserResponse();
166
151
```
167
152
168
-
>**Note:** The safe cast to `UserResponse` is needed because is a subtype of `UserResponse<TKey>`.
169
-
170
153
## Examples
171
154
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
155
173
156
## 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.
157
+
The **NetDevPack.Identity** was developed to be implemented in **ASP.NET Core**. It support all .NET versions since 3.1.
175
158
176
159
## About
177
160
.NET DevPack.Identity was developed by [Eduardo Pires](http://eduardopires.net.br) under the [MIT license](LICENSE).
0 commit comments