void callApiAsync(String targentStep) { if (AppStoreOnboardApi.tokenInfo.access_token == null) { UnityOAuth.GetAuthorizationCodeAsync(AppStoreOnboardApi.oauthClientId, (response) => { if (response.AuthCode != null) { string authcode = response.AuthCode; UnityWebRequest request = AppStoreOnboardApi.GetAccessToken(authcode); TokenInfo tokenInfoResp = new TokenInfo(); ReqStruct reqStruct = new ReqStruct(); reqStruct.request = request; reqStruct.resp = tokenInfoResp; reqStruct.targetStep = targentStep; requestQueue.Enqueue(reqStruct); } else { Debug.Log("Failed: " + response.Exception.ToString()); isOperationRunning = false; } }); } else { UnityWebRequest request = AppStoreOnboardApi.GetUserId(); UserIdResponse userIdResp = new UserIdResponse(); ReqStruct reqStruct = new ReqStruct(); reqStruct.request = request; reqStruct.resp = userIdResp; reqStruct.targetStep = targentStep; requestQueue.Enqueue(reqStruct); } }
public static void OnLoggedIn() { try { UnityOAuth.GetAuthorizationCodeAsync("marketplace", response => { if (response.AuthCode != null) { Promise.All( Utils .Get <EditorSessionTokenResponse>($"/auth/editor?code={response.AuthCode}") .Then(sessionTokenResponse => { loginSession = sessionTokenResponse.loginSessionToken; currentUserId = sessionTokenResponse.userId; loggedIn = true; Utils.Get <DiscoverChannelsResponse>( "/api/connectapp/channels?discover=true" ).Then(discoverResponse => { foreach (var key in discoverResponse.channelMap.Keys) { if (!discoverResponse.channelMap[key].groupId.IsNullOrEmpty()) { discoverResponse.channelMap[key].topic = discoverResponse .groupFullMap[discoverResponse.channelMap[key].groupId].description; } } DiscoverChannels.AddRange( discoverResponse.discoverList .Select(channelId => discoverResponse.channelMap[channelId]) ); UpdateWindowCanvas(); }); UpdateWindowCanvas(); }), InitializeWebSocket() ).Then(SendConnectFrame); } }); } catch (Exception exception) { if (exception.Message != "User is not logged in or user status invalid.") { OnLoggedIn(); } } }
static void GetAuthCode(Action <string, Exception> done) { if (s_AuthCode != null) { done(s_AuthCode, null); return; } UnityOAuth.GetAuthorizationCodeAsync("packman", response => { if (response.Exception != null) { done(null, response.Exception); return; } s_AuthCode = response.AuthCode; done(response.AuthCode, null); }); }
private void GetAuthCode() { if (!string.IsNullOrEmpty(m_UserInfo.authCode)) { GetAccessToken(); return; } if (m_AuthCodeRequested) { return; // a request is already running, no need to recall } m_AuthCodeRequested = true; try { UnityOAuth.GetAuthorizationCodeAsync(kServiceId, authCodeResponse => { if (authCodeResponse.AuthCode != null) { m_UserInfo.authCode = authCodeResponse.AuthCode; GetAccessToken(); } else { m_UserInfo.authCode = ""; m_UserInfo.errorMessage = authCodeResponse.Exception.ToString(); OnDoneFetchUserInfo(); } m_AuthCodeRequested = false; }); } catch (Exception e) { m_UserInfo.authCode = ""; m_UserInfo.errorMessage = e.Message; OnDoneFetchUserInfo(); m_AuthCodeRequested = false; } }
public virtual void GetAuthorizationCodeAsync(string clientId, Action <UnityOAuth.AuthCodeResponse> callback) { UnityOAuth.GetAuthorizationCodeAsync(clientId, callback); }