本文整理汇总了Java中com.microsoft.alm.secret.TokenPair类的典型用法代码示例。如果您正苦于以下问题:Java TokenPair类的具体用法?Java TokenPair怎么用?Java TokenPair使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TokenPair类属于com.microsoft.alm.secret包,在下文中一共展示了TokenPair类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: removeOAuth2Token
import com.microsoft.alm.secret.TokenPair; //导入依赖的package包/类
public static void removeOAuth2Token(final boolean force) {
final Authenticator authenticator =
OAuth2Authenticator.getAuthenticator(CLIENT_ID, REDIRECT_URL, accessTokenStore);
final String tokenKey =
authenticator.getUriToKeyConversion().convert(URIUtils.VSTS_ROOT_URL, authenticator.getAuthType());
final TokenPair oauth2TokenPair = accessTokenStore.get(tokenKey);
if (oauth2TokenPair != null && oauth2TokenPair.AccessToken != null) {
final String token = oauth2TokenPair.AccessToken.Value;
if (force || !isOAuth2TokenValid(token)) {
accessTokenStore.delete(tokenKey);
}
}
}
示例2: completeSignIn
import com.microsoft.alm.secret.TokenPair; //导入依赖的package包/类
/**
* Generates a new server context with session token information for VSO and saves it as the active context
*
* @param context
* @return
*/
public ServerContext completeSignIn(final ServerContext context) {
if (context.getType() == ServerContext.Type.TFS) {
//get authenticated user for the collection since user Id is different when authenticated to server vs collection
return ServerContextManager.getInstance().validateServerConnection(context);
} else {
final ServerContext effectiveContext;
final AuthenticationInfo authenticationInfo = context.getAuthenticationInfo();
if (AuthenticationInfo.CredsType.AccessToken.equals(authenticationInfo.getType())) {
final TokenPair tokenPair
= new TokenPair(authenticationInfo.getPassword(), authenticationInfo.getRefreshToken());
final AuthenticationInfo patBackedAuthenticationInfo
= VsoAuthInfoProvider.getProvider().getAuthenticationInfo(context.getServerUri(), tokenPair);
effectiveContext = new ServerContextBuilder(context).authentication(patBackedAuthenticationInfo).build();
} else {
effectiveContext = context;
}
ServerContextManager.getInstance().add(effectiveContext);
return effectiveContext;
}
}
示例3: interactiveLogon
import com.microsoft.alm.secret.TokenPair; //导入依赖的package包/类
/**
* Opens an interactive logon prompt to acquire acquire an authentication token from the
* Microsoft Live authentication and identity service.
*
* @param targetUri
* The uniform resource indicator of the resource access tokens are being requested for.
*
* @param requireCompactToken
* True if a compact access token is required; false if a standard token is acceptable.
*
* @return True if successful; otherwise false.
*/
@Override public boolean interactiveLogon(URI targetUri, boolean requireCompactToken)
{
final String QueryParameters = "domain_hint=live.com&display=popup&site_id=501454&nux=1";
BaseSecureStore.validateTargetUri(targetUri);
Trace.writeLine("VsoMsaAuthentication::InteractiveLogon");
TokenPair tokens;
if ((tokens = this.VsoAuthority.acquireToken(targetUri, this.ClientId, this.Resource, RedirectUri, QueryParameters)) != null)
{
Trace.writeLine(" token successfully acquired.");
this.storeRefreshToken(targetUri, tokens.RefreshToken);
return this.generatePersonalAccessToken(targetUri, tokens.AccessToken, requireCompactToken);
}
Trace.writeLine(" failed to acquire token.");
return false;
}
开发者ID:Microsoft,项目名称:Git-Credential-Manager-for-Mac-and-Linux,代码行数:34,代码来源:VsoMsaAuthentication.java
示例4: deviceLogon
import com.microsoft.alm.secret.TokenPair; //导入依赖的package包/类
public boolean deviceLogon(final URI targetUri, final boolean requestCompactToken, final Action<DeviceFlowResponse> callback)
{
BaseSecureStore.validateTargetUri(targetUri);
Trace.writeLine("VsoMsaAuthentication::deviceLogon");
TokenPair tokens;
if ((tokens = this.VsoAuthority.acquireToken(targetUri, this.ClientId, this.Resource, RedirectUri, callback)) != null)
{
Trace.writeLine(" token successfully acquired.");
this.storeRefreshToken(targetUri, tokens.RefreshToken);
return this.generatePersonalAccessToken(targetUri, tokens.AccessToken, requestCompactToken);
}
Trace.writeLine(" failed to acquire token.");
return false;
}
开发者ID:Microsoft,项目名称:Git-Credential-Manager-for-Mac-and-Linux,代码行数:20,代码来源:VsoMsaAuthentication.java
示例5: interactiveLogon
import com.microsoft.alm.secret.TokenPair; //导入依赖的package包/类
/**
* <p>Creates an interactive logon session, using ADAL secure browser GUI, which
* enables users to authenticate with the Azure tenant and acquire the necessary access
* tokens to exchange for a VSO personal access token.</p>
* <p>Tokens acquired are stored in the secure secret stores provided during
* initialization.</p>
*
* @param targetUri The unique identifier for the resource for which access is to
* be acquired.
* @param requestCompactToken <p>Requests a compact format personal access token; otherwise requests a standard
* personal access token.</p>
* <p>Compact tokens are necessary for clients which have restrictions on the size of
* the basic authentication header which they can create (example: Git).</p>
* @return True if a authentication and personal access token acquisition was successful; otherwise false.
*/
public boolean interactiveLogon(final URI targetUri, final boolean requestCompactToken)
{
BaseSecureStore.validateTargetUri(targetUri);
Trace.writeLine("VsoAadAuthentication::interactiveLogon");
TokenPair tokens;
if ((tokens = this.VsoAuthority.acquireToken(targetUri, this.ClientId, this.Resource, RedirectUri, (String) null)) != null)
{
Trace.writeLine(" token acquisition succeeded.");
this.storeRefreshToken(targetUri, tokens.RefreshToken);
return this.generatePersonalAccessToken(targetUri, tokens.AccessToken, requestCompactToken);
}
Trace.writeLine(" interactive logon failed");
return false;
}
开发者ID:Microsoft,项目名称:Git-Credential-Manager-for-Mac-and-Linux,代码行数:35,代码来源:VsoAadAuthentication.java
示例6: deviceLogon
import com.microsoft.alm.secret.TokenPair; //导入依赖的package包/类
public boolean deviceLogon(final URI targetUri, final boolean requestCompactToken, final Action<DeviceFlowResponse> callback)
{
BaseSecureStore.validateTargetUri(targetUri);
Trace.writeLine("VsoAadAuthentication::deviceLogon");
TokenPair tokens;
if ((tokens = this.VsoAuthority.acquireToken(targetUri, this.ClientId, this.Resource, RedirectUri, callback)) != null)
{
Trace.writeLine(" token successfully acquired.");
this.storeRefreshToken(targetUri, tokens.RefreshToken);
return this.generatePersonalAccessToken(targetUri, tokens.AccessToken, requestCompactToken);
}
Trace.writeLine(" failed to acquire token.");
return false;
}
开发者ID:Microsoft,项目名称:Git-Credential-Manager-for-Mac-and-Linux,代码行数:20,代码来源:VsoAadAuthentication.java
示例7: VsoAuthInfoProvider
import com.microsoft.alm.secret.TokenPair; //导入依赖的package包/类
private VsoAuthInfoProvider() {
accessTokenStore = new InsecureInMemoryStore<TokenPair>();
tokenStore = new InsecureInMemoryStore<Token>();
deviceFlowResponsePrompt = PluginServiceProvider.getInstance().getDeviceFlowResponsePrompt();
vstsPatAuthenticator = new VstsPatAuthenticator(CLIENT_ID, REDIRECT_URL, accessTokenStore, tokenStore);
}
示例8: acquireToken
import com.microsoft.alm.secret.TokenPair; //导入依赖的package包/类
public TokenPair acquireToken(final URI targetUri, final String clientId, final String resource, final URI redirectUri, final Action<DeviceFlowResponse> callback)
{
Debug.Assert(targetUri != null && targetUri.isAbsolute(), "The targetUri parameter is null or invalid");
Debug.Assert(!StringHelper.isNullOrWhiteSpace(clientId), "The clientId parameter is null or empty");
Debug.Assert(!StringHelper.isNullOrWhiteSpace(resource), "The resource parameter is null or empty");
Debug.Assert(callback != null, "The callback parameter is null");
Trace.writeLine("AzureAuthority::acquireToken");
_azureDeviceFlow.setResource(resource);
_azureDeviceFlow.setRedirectUri(redirectUri);
final StringBuilder sb = new StringBuilder(authorityHostUrl);
sb.append("/oauth2/devicecode");
final URI deviceEndpoint = URI.create(sb.toString());
final DeviceFlowResponse response = _azureDeviceFlow.requestAuthorization(deviceEndpoint, clientId, null);
callback.call(response);
TokenPair tokens = null;
final URI tokenEndpoint = createTokenEndpointUri(authorityHostUrl);
try
{
tokens = _azureDeviceFlow.requestToken(tokenEndpoint, clientId, response);
Trace.writeLine(" token acquisition succeeded.");
}
catch (final AuthorizationException e)
{
Trace.writeLine(" token acquisition failed: ", e);
}
return tokens;
}
示例9: getAuthenticationInfoAsync
import com.microsoft.alm.secret.TokenPair; //导入依赖的package包/类
@Override
public void getAuthenticationInfoAsync(String serverUri, final AuthenticationInfoCallback callback) {
final SettableFuture<AuthenticationInfo> authenticationInfoFuture = SettableFuture.<AuthenticationInfo>create();
// Callback for the Device Flow dialog to cancel the current authenticating process.
// Normally this is hooked up to the cancel button so if user cancels, we do not wait forever in
// a polling loop.
final Action<String> cancellationCallback = new Action<String>() {
@Override
public void call(final String reasonForCancel) {
authenticationInfoFuture.setException(new AuthorizationException(reasonForCancel));
}
};
// Must share the same accessTokenStore with the member variable vstsPatAuthenticator to avoid prompt the user
// when we generate PersonalAccessToken
final OAuth2Authenticator.OAuth2AuthenticatorBuilder oAuth2AuthenticatorBuilder = new OAuth2Authenticator.OAuth2AuthenticatorBuilder()
.withClientId(CLIENT_ID)
.redirectTo(REDIRECT_URL)
.backedBy(accessTokenStore)
.manage(OAuth2Authenticator.MANAGEMENT_CORE_RESOURCE)
.withDeviceFlowCallback(deviceFlowResponsePrompt.getCallback(cancellationCallback));
final OAuth2Authenticator oAuth2Authenticator = oAuth2AuthenticatorBuilder.build();
final URI encodedServerUri = UrlHelper.createUri(serverUri);
final TokenPair tokenPair = oAuth2Authenticator.getOAuth2TokenPair(encodedServerUri, PromptBehavior.AUTO);
try {
final AuthenticationInfo authenticationInfo = getAuthenticationInfo(encodedServerUri, tokenPair);
if (authenticationInfo != null) {
authenticationInfoFuture.set(authenticationInfo);
} else {
authenticationInfoFuture.setException(new TeamServicesException(TeamServicesException.KEY_VSO_AUTH_FAILED));
}
} catch (Throwable t) {
authenticationInfoFuture.setException(t);
}
Futures.addCallback(authenticationInfoFuture, callback);
}
示例10: getAuthenticationInfo
import com.microsoft.alm.secret.TokenPair; //导入依赖的package包/类
public AuthenticationInfo getAuthenticationInfo(final URI serverUri, final TokenPair tokenPair) {
if (tokenPair != null) {
final Client client = RestClientHelper.getClient(serverUri.toString(), tokenPair.AccessToken.Value);
if (client != null) {
//Or we could reconsider the name of the token. Now we call Profile endpoint just to get the email address
//which is used in token description, but do we need it? User can only view PATs after they login, and
//at that time user knows which account/email they are logged in under already. So the email provides
//no additional value.
final AccountHttpClient accountHttpClient
= new MyHttpClient(client, OAuth2Authenticator.APP_VSSPS_VISUALSTUDIO);
final Profile me = accountHttpClient.getMyProfile();
final String emailAddress = me.getCoreAttributes().getEmailAddress().getValue();
final String tokenDescription = AuthHelper.getTokenDescription(emailAddress);
if (serverUri.equals(OAuth2Authenticator.APP_VSSPS_VISUALSTUDIO)) {
logger.debug("Creating authenticationInfo backed by AccessToken for: {}", serverUri);
return new AuthenticationInfo(
me.getId().toString(),
tokenPair.AccessToken.Value,
serverUri.toString(),
emailAddress,
CredsType.AccessToken,
tokenPair.RefreshToken.Value);
} else {
logger.debug("Getting a PersonalAccessToken for: {}", serverUri);
final Token token = vstsPatAuthenticator.getPersonalAccessToken(
serverUri,
VsoTokenScope.AllScopes,
tokenDescription,
PromptBehavior.AUTO,
tokenPair);
if (token != null) {
logger.debug("Creating authenticationInfo backed by PersonalAccessToken for: {}", serverUri);
return new AuthenticationInfo(
me.getId().toString(),
token.Value,
serverUri.toString(),
emailAddress,
CredsType.PersonalAccessToken,
null);
} else {
logger.warn("Failed to get a Personal Access Token");
}
}
} else {
logger.warn("Failed to get authenticated jaxrs client.");
}
} else {
logger.warn("Failed to get AuthenticationInfo because AccessToken is null.");
}
return null;
}
示例11: refreshCredentials
import com.microsoft.alm.secret.TokenPair; //导入依赖的package包/类
/**
* Attempts to generate a new personal access token (credentials) via use of a stored
* Azure refresh token, identified by the target resource.
*
* @param targetUri The 'key' by which to identify the refresh token.
* @param requireCompactToken Generates a compact token if true; generates a self
* describing token if false.
* @return True if successful; false otherwise.
*/
public boolean refreshCredentials(final URI targetUri, final boolean requireCompactToken)
{
BaseSecureStore.validateTargetUri(targetUri);
Trace.writeLine("BaseVsoAuthentication::refreshCredentials");
try
{
TokenPair tokens = null;
AtomicReference<Token> refreshToken = new AtomicReference<Token>();
// attempt to read from the local store
if (this.AdaRefreshTokenStore.readToken(targetUri, refreshToken))
{
if ((tokens = this.VsoAuthority.acquireTokenByRefreshToken(targetUri, this.ClientId, this.Resource, refreshToken.get())) !=
null)
{
Trace.writeLine(" Azure token found in primary cache.");
this.TenantId = tokens.AccessToken.getTargetIdentity();
return this.generatePersonalAccessToken(targetUri, tokens.AccessToken, requireCompactToken);
}
}
AtomicReference<Token> federatedAuthToken = new AtomicReference<Token>();
// attempt to utilize any fedauth tokens captured by the IDE
if (this.VsoIdeTokenCache.readToken(targetUri, federatedAuthToken))
{
Trace.writeLine(" federated auth token found in IDE cache.");
return this.generatePersonalAccessToken(targetUri, federatedAuthToken.get(), requireCompactToken);
}
}
catch (final Exception exception)
{
Debug.Assert(false, exception.getMessage());
}
Trace.writeLine(" failed to refresh credentials.");
return false;
}
开发者ID:Microsoft,项目名称:Git-Credential-Manager-for-Mac-and-Linux,代码行数:52,代码来源:BaseVsoAuthentication.java
示例12: acquireTokenByRefreshToken
import com.microsoft.alm.secret.TokenPair; //导入依赖的package包/类
/**
* Acquires an access token from the authority using a previously acquired refresh token.
*
* @param targetUri The uniform resource indicator of the resource access tokens are being requested for.
* @param clientId Identifier of the client requesting the token.
* @param resource Identifier of the target resource that is the recipient of the requested token.
* @param refreshToken The {@link Token} of type {@link TokenType#Refresh}.
* @return If successful, a {@link TokenPair}; otherwise null.
*/
public TokenPair acquireTokenByRefreshToken(final URI targetUri, final String clientId, final String resource, final Token refreshToken)
{
throw new NotImplementedException(449243);
}
示例13: buildTokenPair
import com.microsoft.alm.secret.TokenPair; //导入依赖的package包/类
/**
* Allows subclasses to construct a subclass of {@link TokenPair} with extra metadata, etc.
*
* @param responseText the JSON response received from the token endpoint.
*
* @return a {@link TokenPair} (or subclass thereof).
*/
protected TokenPair buildTokenPair(final String responseText) {
final TokenPair tokenPair = new TokenPair(responseText);
return tokenPair;
}
示例14: requestToken
import com.microsoft.alm.secret.TokenPair; //导入依赖的package包/类
/**
* The client polls the authorization server's token endpoint repeatedly
* until the end-user grants or denies the request, or the verification
* code expires.
*
* @param tokenEndpoint the authorization server's
* token endpoint as described in Section 4.1.1 of RFC6749.
* @param clientId the client identifier as described in Section 2.2 of RFC6749.
* @param deviceFlowResponse the response obtained from
* {@link #requestAuthorization(URI, String, String)}.
* @return a pair of tokens.
* @throws AuthorizationException the end-user denied the request,
* or the verification code expired.
*
* @see "steps (E) and (F) of the Device Flow"
*/
TokenPair requestToken(final URI tokenEndpoint, String clientId, final DeviceFlowResponse deviceFlowResponse) throws AuthorizationException;
示例15: acquireToken
import com.microsoft.alm.secret.TokenPair; //导入依赖的package包/类
TokenPair acquireToken(final URI targetUri, final String clientId, final String resource, final URI redirectUri, final String queryParameters);