use of com.instructure.canvasapi.utilities.LinkHeaders in project instructure-android by instructure.
the class OAuthWebLogin method removeFromPreviouslySignedInUsers.
public static boolean removeFromPreviouslySignedInUsers(SignedInUser signedInUser, final Context context, String preferenceKey) {
if (TextUtils.isEmpty(preferenceKey)) {
prefNameOtherSignedInUsers = Const.KEY_OTHER_SIGNED_IN_USERS_PREF_NAME;
preferenceKey = prefNameOtherSignedInUsers;
}
// Delete Access Token. We don't care about the result.
APIStatusDelegate apiStatusDelegate = APIHelpers.statusDelegateWithContext(context);
OAuthAPI.deleteToken(signedInUser.token, signedInUser.protocol, signedInUser.domain, new CanvasCallback<Response>(apiStatusDelegate) {
@Override
public void cache(Response response) {
}
@Override
public void firstPage(Response response, LinkHeaders linkHeaders, Response response2) {
}
});
// Save Signed In User to sharedPreferences
SharedPreferences sharedPreferences = context.getSharedPreferences(preferenceKey, MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.remove(getGlobalUserId(signedInUser.domain, signedInUser.user));
return editor.commit();
}
use of com.instructure.canvasapi.utilities.LinkHeaders in project instructure-android by instructure.
the class App method logoutUser.
/**
* Log out the currently signed in user. Permanently remove credential information.
*
* @return
*/
public boolean logoutUser() {
// if this has already ran, data is already cleared causing null pointer exceptions
if (APIHelpers.getToken(this) != null && !APIHelpers.getToken(this).equals("")) {
// Delete token from server
// We don't actually care about this coming back. Fire and forget.
CanvasCallback<Response> deleteTokenCallback = new CanvasCallback<Response>(APIHelpers.statusDelegateWithContext(this)) {
@Override
public void cache(Response response) {
}
@Override
public void firstPage(Response response, LinkHeaders linkHeaders, Response response2) {
}
};
OAuthAPI.deleteToken(deleteTokenCallback);
// Remove Signed In User from sharedPreferences
SharedPreferences sharedPreferences = getSharedPreferences(OTHER_SIGNED_IN_USERS_PREF_NAME, MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.remove(getGlobalUserId(APIHelpers.getDomain(this), APIHelpers.getCacheUser(this)));
editor.commit();
// Clear shared preferences, but keep the important stuff.
safeClearSharedPreferences();
// CLear masquerading preferences.
clearMasqueradingPreferences();
// Clear all Shared Preferences.
APIHelpers.clearAllData(this);
}
return true;
}
use of com.instructure.canvasapi.utilities.LinkHeaders in project instructure-android by instructure.
the class ApplicationManager method logoutUser.
/**
* Log out the currently signed in user. Permanently remove credential information.
*
* @return
*/
public boolean logoutUser() {
// if this has already ran, data is already cleared causing null pointer exceptions
if (APIHelpers.getToken(this) != null && !APIHelpers.getToken(this).equals("")) {
// Delete token from server
// We don't actually care about this coming back. Fire and forget.
CanvasCallback<Response> deleteTokenCallback = new CanvasCallback<Response>(APIHelpers.statusDelegateWithContext(this)) {
@Override
public void cache(Response response) {
}
@Override
public void firstPage(Response response, LinkHeaders linkHeaders, Response response2) {
}
};
OAuthAPI.deleteToken(deleteTokenCallback);
// Remove Signed In User from sharedPreferences
SharedPreferences sharedPreferences = getSharedPreferences(OTHER_SIGNED_IN_USERS_PREF_NAME, MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.remove(OAuthWebLogin.getGlobalUserId(APIHelpers.getDomain(this), APIHelpers.getCacheUser(this)));
editor.commit();
// Clear shared preferences, but keep the important stuff.
safeClearSharedPreferences();
// CLear masquerading preferences.
clearMasqueradingPreferences();
// Clear all Shared Preferences.
APIHelpers.clearAllData(this);
}
return true;
}
use of com.instructure.canvasapi.utilities.LinkHeaders in project instructure-android by instructure.
the class OAuthWebLogin method setupCallback.
public void setupCallback() {
mobileVerifyCallback = new CanvasCallback<DomainVerificationResult>(APIHelpers.statusDelegateWithContext(OAuthWebLogin.this)) {
@Override
public void cache(DomainVerificationResult domainVerificationResult) {
}
@Override
public void firstPage(DomainVerificationResult domainVerificationResult, LinkHeaders linkHeaders, Response response) {
if (domainVerificationResult.getResult() == DomainVerificationResult.DomainVerificationCode.Success) {
// Domain is now verified.
// save domain to the preferences.
String domain = "";
// mobile verify can change the hostname we need to use
if (domainVerificationResult.getBase_url() != null && !domainVerificationResult.getBase_url().equals("")) {
domain = domainVerificationResult.getBase_url();
} else {
domain = url;
}
// The domain gets set afterwards in SetUpInstance, but domain is required a bit before that works.
APIHelpers.setDomain(OAuthWebLogin.this, domain);
client_id = domainVerificationResult.getClient_id();
client_secret = domainVerificationResult.getClient_secret();
// Get the protocol
api_protocol = domainVerificationResult.getProtocol();
// Set the protocol
APIHelpers.setProtocol(domainVerificationResult.getProtocol(), OAuthWebLogin.this);
// Get device name for the login request.
String deviceName = Build.MODEL;
if (deviceName == null || deviceName.equals("")) {
deviceName = getString(R.string.unknownDevice);
}
// Remove spaces
deviceName = deviceName.replace(" ", "_");
// changed for the online update to have an actual formatted login page
authenticationURL = api_protocol + "://" + domain + "/login/oauth2/auth?client_id=" + client_id + "&response_type=code&redirect_uri=urn:ietf:wg:oauth:2.0:oob&mobile=1";
authenticationURL += "&purpose=" + deviceName;
if (canvas_login == 1) {
authenticationURL += "&canvas_login=1";
} else if (canvas_login == 2) {
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setCookie(api_protocol + "://" + domain, "canvas_sa_delegated=1");
}
web.loadUrl(authenticationURL);
} else {
// Error message
int errorId;
if (domainVerificationResult.getResult() == DomainVerificationResult.DomainVerificationCode.GeneralError) {
errorId = R.string.mobileVerifyGeneral;
} else if (domainVerificationResult.getResult() == DomainVerificationResult.DomainVerificationCode.DomainNotAuthorized) {
errorId = R.string.mobileVerifyDomainUnauthorized;
} else if (domainVerificationResult.getResult() == DomainVerificationResult.DomainVerificationCode.UnknownUserAgent) {
errorId = R.string.mobileVerifyUserAgentUnauthorized;
} else {
errorId = R.string.mobileVerifyUnknownError;
}
MaterialDialog.Builder builder = new MaterialDialog.Builder(OAuthWebLogin.this);
builder.title(R.string.errorOccurred);
builder.content(errorId);
builder.cancelable(true);
builder.positiveColor(Color.BLACK);
MaterialDialog dialog = builder.build();
dialog.show();
}
}
};
getToken = new CanvasCallback<OAuthToken>(APIHelpers.statusDelegateWithContext(OAuthWebLogin.this)) {
@Override
public void cache(OAuthToken oAuthToken, LinkHeaders linkHeaders, Response response) {
}
@Override
public void firstPage(OAuthToken oAuthToken, LinkHeaders linkHeaders, Response response) {
// Set up the rest adapter and such.
APIHelpers.setToken(getContext(), oAuthToken.getAccess_token());
CanvasRestAdapter.setupInstance(getContext(), oAuthToken.getAccess_token(), APIHelpers.loadProtocol(getContext()) + "://" + APIHelpers.getDomain(getContext()));
// save the successful domain to be remembered for later
JSONArray domains = SavedDomains.getSavedDomains(OAuthWebLogin.this, prefNamePreviousDomain);
String domain = APIHelpers.getDomain(OAuthWebLogin.this);
domains.put(domain);
// save the new domain
SavedDomains.setSavedDomains(OAuthWebLogin.this, domains, prefNamePreviousDomain);
// Set the last used domain.
setLastSignedInDomain(domain, OAuthWebLogin.this);
// We now need to get the cache user
UserAPI.getSelf(new UserCallback(APIHelpers.statusDelegateWithContext(OAuthWebLogin.this)) {
@Override
public void cachedUser(User user) {
}
@Override
public void user(User user, Response response) {
Intent intent = OAuthWebLogin.this.getIntent();
intent.putExtra(URLSignIn.loggedInIntent, true);
if (passedURI != null) {
intent.putExtra(Const.PASSED_URI, passedURI);
}
OAuthWebLogin.this.setResult(RESULT_OK, intent);
OAuthWebLogin.this.finish();
}
});
}
@Override
public boolean onFailure(RetrofitError retrofitError) {
if (!specialCase) {
Toast.makeText(OAuthWebLogin.this, R.string.errorOccurred, Toast.LENGTH_SHORT).show();
} else {
specialCase = false;
}
web.loadUrl(authenticationURL);
return true;
}
};
}
use of com.instructure.canvasapi.utilities.LinkHeaders in project instructure-android by instructure.
the class ZendeskDialogStyled method saveZendeskTicket.
public void saveZendeskTicket() {
String comment = descriptionEditText.getText().toString();
String subject = subjectEditText.getText().toString();
if (comment.isEmpty() || subject.isEmpty()) {
Toast.makeText(getContext(), R.string.empty_feedback, Toast.LENGTH_LONG).show();
return;
}
// contact the user
if (fromLogin) {
if (emailAddressEditText.getText() != null && emailAddressEditText.getText().toString() != null) {
User user = new User();
user.setEmail(emailAddressEditText.getText().toString());
APIHelpers.setCacheUser(getActivity(), user);
}
}
final String email = APIHelpers.getCacheUser(getActivity()).getEmail();
String domain = APIHelpers.getDomain(getActivity());
if (domain == null) {
domain = DEFAULT_DOMAIN;
}
// add device info to comment
// try to get the version number and version code
PackageInfo pInfo = null;
String versionName = "";
int versionCode = 0;
try {
pInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0);
versionName = pInfo.versionName;
versionCode = pInfo.versionCode;
} catch (PackageManager.NameNotFoundException e) {
Utils.d(e.getMessage());
}
String deviceInfo = "";
deviceInfo += getString(R.string.device) + " " + Build.MANUFACTURER + " " + Build.MODEL + "\n" + getString(R.string.osVersion) + " " + Build.VERSION.RELEASE + "\n" + getString(R.string.versionNum) + ": " + versionName + " " + versionCode + "\n" + getString(R.string.zendesk_severityText) + " " + getUserSeveritySelectionTag() + "\n" + getString(R.string.utils_installDate) + " " + getInstallDateString() + "\n\n";
comment = deviceInfo + comment;
if (mUseDefaultDomain) {
ErrorReportAPI.postGenericErrorReport(subject, domain, email, comment, getUserSeveritySelectionTag(), new CanvasCallback<ErrorReportResult>((APIStatusDelegate) resultListener) {
@Override
public void firstPage(ErrorReportResult errorReportResult, LinkHeaders linkHeaders, Response response) {
resetCachedUser();
resultListener.onTicketPost();
}
@Override
public boolean onFailure(RetrofitError retrofitError) {
resetCachedUser();
resultListener.onTicketError();
return super.onFailure(retrofitError);
}
});
} else {
ErrorReportAPI.postErrorReport(subject, domain, email, comment, getUserSeveritySelectionTag(), new CanvasCallback<ErrorReportResult>((APIStatusDelegate) resultListener) {
@Override
public void cache(ErrorReportResult errorReportResult) {
resetCachedUser();
}
@Override
public void firstPage(ErrorReportResult errorReportResult, LinkHeaders linkHeaders, Response response) {
cache(errorReportResult);
resultListener.onTicketPost();
}
@Override
public boolean onFailure(RetrofitError retrofitError) {
resetCachedUser();
resultListener.onTicketError();
return super.onFailure(retrofitError);
}
});
}
}
Aggregations