File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ public static PlutoUser auth(String token) throws PlutoException {
3737 JSONObject payload = JSONObject .fromObject (new String (Base64 .getDecoder ().decode (parts [1 ]), "utf-8" ));
3838 // Verify the appId of the jwt token.
3939 if (!payload .getString ("appId" ).equals (shared .appId )) {
40- ;
40+ throw new PlutoException ( PlutoErrorCode . appIdError ) ;
4141 }
4242 Long expire = payload .getLong ("expire_time" ) * 1000 ;
4343 if (expire < System .currentTimeMillis ()) {
Original file line number Diff line number Diff line change 33import net .sf .json .JSONArray ;
44import net .sf .json .JSONObject ;
55
6+ import java .util .ArrayList ;
7+ import java .util .List ;
8+
69public class PlutoUser {
710 private long userId ;
811 private String deviceId ;
9- private String [] scopes ;
12+ private List < String > scopes ;
1013 private LoginType loginType ;
1114
1215 public long getUserId () {
@@ -17,6 +20,10 @@ public String getDeviceId() {
1720 return deviceId ;
1821 }
1922
23+ public List <String > getScopes () {
24+ return scopes ;
25+ }
26+
2027 public LoginType getLoginType () {
2128 return loginType ;
2229 }
@@ -25,9 +32,9 @@ public PlutoUser(JSONObject payload) {
2532 userId = payload .getLong ("userId" );
2633 deviceId = payload .getString ("deviceId" );
2734 JSONArray scopeArray = payload .getJSONArray ("scopes" );
28- scopes = new String [ scopeArray . size ()] ;
35+ scopes = new ArrayList <>() ;
2936 for (int i = 0 ; i < scopeArray .size (); i ++) {
30- scopes [ i ] = scopeArray .getString (i );
37+ scopes . add ( scopeArray .getString (i ) );
3138 }
3239 loginType = LoginType .fromIdentifier (payload .getString ("login_type" ));
3340 }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ package org .mushare .pluto ;
2+
3+ import org .junit .Test ;
4+
5+ import static org .junit .Assert .assertTrue ;
6+
7+ public class PlutoTest {
8+
9+ @ Test
10+ public void testAuth () {
11+ Pluto .setup ("https://staging.easyjapanese-api-gateway.mushare.cn/pluto/" , "org.mushare.easyjapanese" );
12+ String scope = "easyjapanese.admin" ;
13+ String token = "eyJ0eXBlIjoiand0IiwiYWxnIjoicnNhIn0.eyJ0eXBlIjoiYWNjZXNzIiwiY3JlYXRlX3RpbWUiOjE1ODQ3MjIyMjQsImV4cGlyZV90aW1lIjoxNTg0NzI1ODI0LCJ1c2VySWQiOjMsImRldmljZUlkIjoiQ0Y0Mzc5MzMtQ0MyMS00QUFCLTgxNjEtMUU1MTVCNjQxQTU5IiwiYXBwSWQiOiJvcmcubXVzaGFyZS5lYXN5amFwYW5lc2UiLCJzY29wZXMiOlsiZWFzeWphcGFuZXNlLmFkbWluIl0sImxvZ2luX3R5cGUiOiJtYWlsIn0.V6HVNGsRvzLkgCzPxV3JH9H1GqF/ycNrKQDp/mzq/OdCOy1v8cu/O9HCjtW2J5NZuYgdtletEuoEdIQBUqtRHAseRPcyUmddWf3NxCHcqpAQZW2hJzp8WRgfP2Gug+O++IBoysntYz6FWSLUqw0HzGlU46J4jQnmzWvW/MR/mvM/7IWS5mtPM8DftlI3hBeeXH6FRKMtRbzr4PD0sTb/rSpJPtcs2YXmlj8C5DOhZd2XQjqnA7HhA3MZ2PAy6hkeZ99qyDUZav5SoOQQ8qCNbGDg/nQbeIaUHcg4Fx0F5lIlFAyHHaEkyhwSN4dLI+4ZD1rIxIXLH+uzcWOCYTIxag" ;
14+ PlutoUser user = Pluto .auth (token );
15+ assertTrue ("testAuth should return 'true'" , user .getScopes ().contains (scope ));
16+ }
17+
18+ }
You can’t perform that action at this time.
0 commit comments