@@ -70,7 +70,7 @@ public class Runtime{
7070 }
7171
7272 if let uuid = options [ " uuid " ] , secret = options [ " secret " ] {
73- let tokenSign = JWT . encode ( [ " uuid " : uuid] , algorithm: . HS256( secret) )
73+ let tokenSign = JWT . encode ( [ " uuid " : uuid, " type " : " device " ] , algorithm: . HS256( secret) )
7474 login ( [ " token " : tokenSign] ) . then { ( auth: Auth ) -> Void in
7575 self . initNetwork ( auth)
7676 if self . enableSocket {
@@ -83,8 +83,8 @@ public class Runtime{
8383 }
8484 }
8585
86- if let deviceUuid = options [ " deviceUuid " ] , secret = options [ " secret " ] {
87- let tokenSign = JWT . encode ( [ " uuid " : deviceUuid ] , algorithm: . HS256( secret) )
86+ if let uuid = options [ " deviceUuid " ] , secret = options [ " secret " ] {
87+ let tokenSign = JWT . encode ( [ " uuid " : uuid , " type " : " device " ] , algorithm: . HS256( secret) )
8888 login ( [ " token " : tokenSign] ) . then { ( auth: Auth ) -> Void in
8989 self . initNetwork ( auth)
9090 if self . enableSocket {
@@ -98,8 +98,36 @@ public class Runtime{
9898
9999 }
100100
101- if let networkUuid = options [ " networkUuid " ] , apiKey = options [ " apiKey " ] {
102- let tokenSign = JWT . encode ( [ " networkUuid " : networkUuid] , algorithm: . HS256( apiKey) )
101+ if let uuid = options [ " uuid " ] , apiKey = options [ " apiKey " ] {
102+ let tokenSign = JWT . encode ( [ " uuid " : uuid, " type " : " consumerApp " ] , algorithm: . HS256( apiKey) )
103+ login ( [ " token " : tokenSign] ) . then { ( auth: Auth ) -> Void in
104+ self . initNetwork ( auth)
105+ if self . enableSocket {
106+ socketManager. start_socket ( ) . then { ( result: Bool ) -> Void in
107+ if result{
108+ fulfill ( true )
109+ }
110+ }
111+ }
112+ }
113+ }
114+
115+ if let uuid = options [ " consumerAppUuid " ] , apiKey = options [ " apiKey " ] {
116+ let tokenSign = JWT . encode ( [ " uuid " : uuid, " type " : " consumerApp " ] , algorithm: . HS256( apiKey) )
117+ login ( [ " token " : tokenSign] ) . then { ( auth: Auth ) -> Void in
118+ self . initNetwork ( auth)
119+ if self . enableSocket {
120+ socketManager. start_socket ( ) . then { ( result: Bool ) -> Void in
121+ if result{
122+ fulfill ( true )
123+ }
124+ }
125+ }
126+ }
127+ }
128+
129+ if let uuid = options [ " networkUuid " ] , apiKey = options [ " apiKey " ] {
130+ let tokenSign = JWT . encode ( [ " uuid " : uuid, " type " : " consumerApp " ] , algorithm: . HS256( apiKey) )
103131 login ( [ " token " : tokenSign] ) . then { ( auth: Auth ) -> Void in
104132 self . initNetwork ( auth)
105133 if self . enableSocket {
0 commit comments