/// <summary> /// Deauthorizes the current user and clears any persistent state with regards to the current user. /// </summary> /// <remarks>Since: 0.1.0</remarks> public void Deauthorize() { jwtAccessTokenStore = null; isAuthorized = false; SCFCore.Instance.m_core.setValue("jwtKey", ""); UnRegisterToCore(); SCFCore.Instance.UnLoad(); }
/// <summary> /// Initializes a new instance of the <see cref="JWTAuthenticator"/> class. /// </summary> /// <remarks>Since: 0.1.0</remarks> public JWTAuthenticator() { this.isRegisteredToCore = false; this.jwt = null; this.client = new JWTAuthClient(); this.jwtAccessTokenStore = null; this.isAuthorized = false; RegisterToCore(); }
/// <summary> /// Returns an access token of this authenticator. /// This may involve long-running operations such as service calls, /// but may also return immediately. The application should not make assumptions about how quickly this completes. /// If the access token could not be retrieved then the completion handler will be called with null. /// </summary> /// <param name="completionHandler">The completion event handler.</param> /// <remarks>Since: 0.1.0</remarks> public void AccessToken(Action <WebexApiEventArgs <string> > completionHandler) { // access token is valid now, just return it. string token = GetUnexpiredAccessToken(); if (token != null) { completionHandler(new WebexApiEventArgs <string>(true, null, token)); return; } SdkLogger.Instance.Debug("get an new access token"); // check JWT if valid. if (null == GetUnexpiredJwt()) { SdkLogger.Instance.Error("the jwt has expired."); completionHandler(new WebexApiEventArgs <string>(false, null, null)); return; } // Fetch access token this.client.FetchTokenFromJWTAsync(this.jwt, this, (response => { // Success Get AccessToken if (response != null && response.IsSuccess && response.Data != null) { // Store AccessToken string rspToken = response.Data.Token; int rspExpiresIn = response.Data.ExpiresIn; this.jwtAccessTokenStore = new JWTAccessToken(rspToken, rspExpiresIn); // Set to Core if (isAuthorized) { SetAccessTokenToCore(rspToken, rspExpiresIn); } SdkLogger.Instance.Info("get jwt access token success."); // Callback to User completionHandler(new WebexApiEventArgs <string>(true, null, this.jwtAccessTokenStore.token)); return; } SdkLogger.Instance.Error("fetch jwt token failed"); // Callback to User completionHandler(new WebexApiEventArgs <string>(false, null, null)); })); }