/// <summary> /// Override the method to retrive the access token for hawaii Guid authentication. /// </summary> /// <param name="callback">callback from event</param> public override void RetriveAccessToken(RetriveAccessTokenComplete callback) { string token = string.Empty; if (!string.IsNullOrEmpty(this.RegistrationId) && !string.IsNullOrEmpty(this.SecretKey)) { if (!string.IsNullOrEmpty(this.ApplicationId)) { // If this app token is not empty, take only id and secret key token = string.Format("{0}:{1}:{2}", this.ApplicationId, this.RegistrationId, this.SecretKey); } else { token = string.Format("{0}:{1}", this.RegistrationId, this.SecretKey); } } else if (!string.IsNullOrEmpty(this.ApplicationId)) { token = this.ApplicationId; } if (!string.IsNullOrEmpty(token)) { this.OnRetriveAccessTokenComplete(string.Format("Basic {0}", Convert.ToBase64String(Encoding.UTF8.GetBytes(token))), null, callback); } else { this.OnRetriveAccessTokenComplete(string.Empty, new InvalidOperationException("Hawaii Guid authentication token cannot be empty string"), callback); } }
/// <summary> /// The callback handler of GetAdmAccessToken event of AdmTokenService. /// </summary> /// <param name="accessToken">The token instance.</param> /// <param name="ex">Coressponding exception if failed to get the access token.</param> /// <param name="callback">callback from event</param> private void TokenService_GetAdmAccessTokenCompleteEvent(AdmAccessToken accessToken, Exception ex, RetriveAccessTokenComplete callback) { if (ex == null) { string token = string.Empty; if (!string.IsNullOrEmpty(this.RegistrationId) && !string.IsNullOrEmpty(this.SecretKey)) { token = string.Format("BEARER {0} {1} {2}", accessToken.AccessToken, this.SecretKey, this.RegistrationId); } else { token = string.Format("BEARER {0}", accessToken.AccessToken); } this.OnRetriveAccessTokenComplete(token, ex, callback); } else { this.OnRetriveAccessTokenComplete(string.Empty, ex, callback); } }
/// <summary> /// Override the method to retrive the access token for Adm authentication. /// </summary> /// <param name="callback">event callback</param> public override void RetriveAccessToken(RetriveAccessTokenComplete callback) { this.tokenService.GetAccessToken(new AdmTokenService.RetriveAdmAccessTokenComplete((accessToken, ex) => { TokenService_GetAdmAccessTokenCompleteEvent(accessToken, ex, callback); })); }
/// <summary> /// Helper method to fire the RetriveAccessTokenCompleteEvent event. /// </summary> /// <param name="accessToken">The accesss token string</param> /// <param name="ex">Coressponding exception if failed to get the access token.</param> /// <param name="callback">callback from event</param> protected virtual void OnRetriveAccessTokenComplete(string accessToken, Exception ex, RetriveAccessTokenComplete callback) { callback(accessToken, ex); }
/// <summary> /// Gets the identity token that is used when communicating with the server. /// </summary> /// <param name="callback">callback from event</param> public abstract void RetriveAccessToken(RetriveAccessTokenComplete callback);