@@ -2,9 +2,13 @@ package api
22
33import (
44 "encoding/json"
5+ "fmt"
6+ "io/ioutil"
7+ "log"
58 "net/http"
69 "time"
710
11+ "github.com/loginradius/lr-cli/cmdutil"
812 "github.com/loginradius/lr-cli/config"
913 "github.com/loginradius/lr-cli/request"
1014)
@@ -62,3 +66,74 @@ func AuthValidateToken() (*ValidateTokenResp, error) {
6266 }
6367 return & resObj , nil
6468}
69+
70+ type AppID struct {
71+ CurrentAppId int `json:"currentAppId"`
72+ }
73+
74+ func CurrentID () (* AppID , error ) {
75+ conf := config .GetInstance ()
76+ config := conf .AdminConsoleAPIDomain + "/auth/config?"
77+ var currentAppId AppID
78+ resp , err := request .Rest (http .MethodGet , config , nil , "" )
79+ if err != nil {
80+ return nil , err
81+ }
82+ err = json .Unmarshal (resp , & currentAppId )
83+ if err != nil {
84+ return nil , err
85+ }
86+
87+ return & currentAppId , nil
88+ }
89+
90+ func SitesBasic (tokens * SitesToken ) error {
91+ conf := config .GetInstance ()
92+ var newToken SitesToken
93+ client := & http.Client {}
94+ basic := conf .AdminConsoleAPIDomain + "/auth/basicsettings?"
95+ req , err := http .NewRequest (http .MethodGet , basic , nil )
96+ if err != nil {
97+ log .Printf ("Could not make request % -v" , err )
98+ }
99+ req .Header .Add ("x-is-loginradius--sign" , tokens .XSign )
100+ req .Header .Add ("x-is-loginradius--token" , tokens .XToken )
101+ req .Header .Add ("x-is-loginradius-ajax" , "true" )
102+ req .Header .Add ("Content-Type" , "application/json; charset=utf-8" )
103+ req .Header .Add ("Origin" , conf .DashboardDomain )
104+ resp , err := client .Do (req )
105+ if err != nil {
106+ log .Printf ("%s" , err .Error ())
107+ }
108+
109+ defer resp .Body .Close ()
110+ bodyBytes , err := ioutil .ReadAll (resp .Body )
111+ if err != nil {
112+ fmt .Print (err .Error ())
113+ }
114+ //obtaining the new tokens
115+ err = json .Unmarshal (bodyBytes , & newToken )
116+ if err != nil {
117+ return err
118+ }
119+ result := LoginResponse {
120+ APIVersion : tokens .APIVersion ,
121+ AppName : tokens .AppName ,
122+ AppID : tokens .AppID ,
123+ Authenticated : true ,
124+ XSign : newToken .XSign , //switching tokens
125+ XToken : newToken .XToken ,
126+ }
127+ resObj , err := json .Marshal (result )
128+ err = cmdutil .DeleteFiles ()
129+ if err != nil {
130+ return err
131+ }
132+ err = cmdutil .StoreCreds (resObj )
133+ if err != nil {
134+ return err
135+ }
136+
137+ return nil
138+
139+ }
0 commit comments