use of com.intellij.credentialStore.Credentials in project intellij-plugins by StepicOrg.
the class StepikAuthManager method setTokenInfo.
private static void setTokenInfo(long userId, @NotNull final TokenInfo tokenInfo) {
String serviceName = StepikProjectManager.class.getName();
String userName = String.valueOf(userId);
CredentialAttributes attributes;
attributes = new CredentialAttributes(serviceName, userName, StepikProjectManager.class, false);
String serializedAuthInfo = stepikApiClient.getJsonConverter().toJson(tokenInfo);
Credentials credentials = new Credentials(attributes.getUserName(), serializedAuthInfo);
PasswordSafe.getInstance().set(attributes, credentials);
setLastUser(userId);
}
use of com.intellij.credentialStore.Credentials in project intellij-plugins by StepicOrg.
the class StepikAuthManager method getTokenInfo.
@NotNull
private static TokenInfo getTokenInfo(long userId, StepikApiClient client) {
if (userId == 0) {
return new TokenInfo();
}
String serviceName = StepikProjectManager.class.getName();
CredentialAttributes attributes = new CredentialAttributes(serviceName, String.valueOf(userId), StepikProjectManager.class, false);
Credentials credentials = PasswordSafe.getInstance().get(attributes);
TokenInfo authInfo = null;
if (credentials != null) {
String password = credentials.getPasswordAsString();
authInfo = client.getJsonConverter().fromJson(password, TokenInfo.class);
}
if (authInfo == null) {
return new TokenInfo();
}
return authInfo;
}
Aggregations