commit | author | age
|
7ecde3
|
1 |
/* |
U |
2 |
http-oauth - OAuth Extensions to jdk.httpserver |
|
3 |
Copyright (C) 2021 Ulrich Hilger |
|
4 |
|
|
5 |
This program is free software: you can redistribute it and/or modify |
|
6 |
it under the terms of the GNU Affero General Public License as |
|
7 |
published by the Free Software Foundation, either version 3 of the |
|
8 |
License, or (at your option) any later version. |
|
9 |
|
|
10 |
This program is distributed in the hope that it will be useful, |
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
GNU Affero General Public License for more details. |
|
14 |
|
|
15 |
You should have received a copy of the GNU Affero General Public License |
|
16 |
along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
17 |
*/ |
|
18 |
package de.uhilger.httpserver.oauth; |
|
19 |
|
|
20 |
import com.google.gson.Gson; |
|
21 |
|
|
22 |
/** |
|
23 |
* Die Klasse LoginResponse modelliert die Antwort auf eine HTTP-Anfrage |
|
24 |
* gemaess Bearer Authentication nach RFC 6750 |
|
25 |
* |
|
26 |
* @author Ulrich Hilger |
|
27 |
* @version 1, 08.6.2021 |
|
28 |
*/ |
|
29 |
public class LoginResponse { |
|
30 |
/* |
|
31 |
HTTP/1.1 200 OK |
|
32 |
Content-Type: application/json;charset=UTF-8 |
|
33 |
Cache-Control: no-store |
|
34 |
Pragma: no-cache |
|
35 |
|
|
36 |
{ |
|
37 |
"access_token":"mF_9.B5f-4.1JqM", |
|
38 |
"token_type":"Bearer", |
|
39 |
"expires_in":3600, |
|
40 |
"refresh_token":"tGzv3JOkF0XG5Qx2TlKWIA" |
|
41 |
} |
|
42 |
*/ |
|
43 |
|
|
44 |
private String access_token; |
|
45 |
private final String token_type = BearerAuthenticator.BEARER; |
|
46 |
private long expires_in; |
|
47 |
private String refresh_token; |
|
48 |
|
a4bee5
|
49 |
/** |
U |
50 |
* Den Token ermitteln |
|
51 |
* @return der Token |
|
52 |
*/ |
7ecde3
|
53 |
public String getToken() { |
U |
54 |
return access_token; |
|
55 |
} |
|
56 |
|
a4bee5
|
57 |
/** |
U |
58 |
* Den Token eintragen |
|
59 |
* @param token der Token |
|
60 |
*/ |
7ecde3
|
61 |
public void setToken(String token) { |
U |
62 |
this.access_token = token; |
|
63 |
} |
|
64 |
|
a4bee5
|
65 |
/** |
U |
66 |
* Den Refresh-Token ermitteln |
|
67 |
* @return der Refreh-Token |
|
68 |
*/ |
7ecde3
|
69 |
public String getRefreshToken() { |
U |
70 |
return refresh_token; |
|
71 |
} |
|
72 |
|
a4bee5
|
73 |
/** |
U |
74 |
* Den Refresh-Token eintragen |
|
75 |
* @param refreshToken der Refresh Token |
|
76 |
*/ |
7ecde3
|
77 |
public void setRefreshToken(String refreshToken) { |
U |
78 |
this.refresh_token = refreshToken; |
|
79 |
} |
|
80 |
|
a4bee5
|
81 |
/** |
U |
82 |
* Den Token-Typ bestimmen |
|
83 |
* @return der Token-Typ |
|
84 |
*/ |
7ecde3
|
85 |
public String getTokenType() { |
U |
86 |
return token_type; |
|
87 |
} |
|
88 |
|
a4bee5
|
89 |
/** |
U |
90 |
* Die Anzahl der Sekunden ermitteln, nach denen der |
|
91 |
* Token ungueltig wird |
|
92 |
* @return die Anzahl Sekunden bis der Token ungueltg wird |
|
93 |
*/ |
7ecde3
|
94 |
public long getExpiresIn() { |
U |
95 |
return expires_in; |
|
96 |
} |
|
97 |
|
a4bee5
|
98 |
/** |
U |
99 |
* Die Anzahl der Sekunden setzen, nach denen der |
|
100 |
* Token ungueltig wird |
|
101 |
* |
|
102 |
* @param seconds die Anzahl Sekunden bis der Token ungueltg wird |
|
103 |
*/ |
7ecde3
|
104 |
public void setExpiresIn(long seconds) { |
U |
105 |
this.expires_in = seconds; |
|
106 |
} |
|
107 |
|
a4bee5
|
108 |
/** |
U |
109 |
* Dieses Objekt nach JSON uebersetzen |
|
110 |
* @return das Objekt in JSON |
|
111 |
*/ |
7ecde3
|
112 |
public String toJson() { |
U |
113 |
Gson gson = new Gson(); |
|
114 |
return gson.toJson(this); |
|
115 |
} |
|
116 |
} |