GoogleAuthException thrown when using audience:server:client_id:<SEERVER_CLIENT_ID> - google-plus-signin

I am using the google plus api to login my user with the oauth2 infrastructure. I want to use backend authentication service. I followed this guide https://developers.google.com/identity/sign-in/android/backend-auth step by step. However every time I call
scope1 = "audience:server:client_id:" + SERVER_CLIENT_ID;
GoogleAuthUtil.getToken(context, account, scope1);
It throws the above exception. I tried all the solutions given by stackoverflow as well as other blogs and nothing seems to change.
Is there a way to verify in more deep the cause of this problem. I mean some debugging tool in "google developer console" or android side to know more specifically whats going on.
logcat output:
V/GLSActivity(3383): AuthDelegateWrapperCreated with selected intent: Intent { cmp=com.google.android.gms/.auth.DefaultAuthDelegateService }
V/AuthAccountOperation(18778): offline access is not requested; requesting access token
I/GLSUser(3383): [GLSUser] getTokenFromCache: [account: <ELLIDED:-15230>, callingPkg: com.clanpid.mobile.restaurant.app, service: oauth2:https://www.googleapis.com/auth/plus.login]
I/GLSUser(3383): [GLSUser] getTokenFromGoogle [account: <ELLIDED:-15230>, callingPkg: com.clanpid.mobile.restaurant.app, service: oauth2:https://www.googleapis.com/auth/plus.login
I/GLSUser(3383): [GLSUser] getAuthtoken(<ELLIDED:-15230>, oauth2:https://www.googleapis.com/auth/plus.login) -> status: null)
I/GLSUser(3383): [GLSUser] Extracting token using key: Auth
W/GLSUser(3383): [GLSUser] Permission for com.clanpid.mobile.restaurant.app to access oauth2:https://www.googleapis.com/auth/plus.login will be managed remotely.
V/AuthAccountOperation(18778): access token request successful
I/GLSUser(3383): [GLSUser] getTokenFromCache: [account: <ELLIDED:-15230>, callingPkg: com.clanpid.mobile.restaurant.app, service: oauth2:https://www.googleapis.com/auth/plus.login]
D/UserAccessTokenFetcher(25646): am.pablo.vc#gmail.com
I/GLSUser(3383): [GLSUser] getTokenFromCache: [account: <ELLIDED:-15230>, callingPkg: com.clanpid.mobile.restaurant.app, service: audience:server:client_id:1074993820719-dlcpq2f2ev9pnlmlghclteakv50ivft1.apps.googleusercontent.com]
I/GLSUser(3383): [GLSUser] getTokenFromGoogle [account: <ELLIDED:-15230>, callingPkg: com.clanpid.mobile.restaurant.app, service: audience:server:client_id:1074993820719-dlcpq2f2ev9pnlmlghclteakv50ivft1.apps.googleusercontent.com
W/GLSActivity(3383): gms.StatusHelper Status from wire: INVALID_AUDIENCE status: null
I/GLSUser(3383): [GLSUser] getAuthtoken(<ELLIDED:-15230>, audience:server:client_id:1074993820719-dlcpq2f2ev9pnlmlghclteakv50ivft1.apps.googleusercontent.com) -> status: UNKNOWN)
I/GLSUser(3383): [GLSUser] Extracting token using key: Auth
W/GLSActivity(3383): gms.StatusHelper Status from wire: INVALID_AUDIENCE status: null
W/System.err(25646): com.google.android.gms.auth.GoogleAuthException: Unknown

try this
final String SCOPES = "https://www.googleapis.com/auth/userinfo.profile";
String token = null;
try {
token = GoogleAuthUtil.getToken(getApplicationContext(),
Plus.AccountApi.getAccountName(mGoogleApiClient),
"oauth2:" + SCOPES);
} catch (IOException e) {
Timber.e(e, "Error retrieving ID token.");
} catch (GoogleAuthException e) {
Timber.e(e, "Error retrieving ID token.");
}

Related

IAM Cannot Access Launch Template

I am using the AWS Node SDK to try and use a launch template to launch an EC2 instance. In the web console for the same user I have access to the Launch Template ID, but in the Node API it tells me the Launch Template with ID does not exist:
version: aws-sdk#2.606.0
Screenshot in AWS Console
Screenshot in my config file
(I've blocked the last few characters for security but they are the same)
This is the Node
AWS = require('aws-sdk');
AWS.config.update({region: global.settings.aws.region});
let instanceParams = {
LaunchTemplate: {
LaunchTemplateId: global.settings.aws.ltId
},
InstanceType: 't2.micro',
MinCount: 1,
MaxCount: 1
};
let instancePromise = new AWS.EC2().runInstances(instanceParams).promise();
instancePromise.then(
function(data) {
console.log(data);
}).catch(
function(err) {
console.error(err, err.stack);
});
This is the error the API returns:
InvalidLaunchTemplateId.NotFound: The specified launch template, with template ID lt-03969d13638b5XXXX, does not exist.
at Request.extractError (/ApplicationPath/node_modules/aws-sdk/lib/services/ec2.js:50:35)
at Request.callListeners (/ApplicationPath/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
at Request.emit (/ApplicationPath/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
at Request.emit (/ApplicationPath/node_modules/aws-sdk/lib/request.js:683:14)
at Request.transition (/ApplicationPath/node_modules/aws-sdk/lib/request.js:22:10)
at AcceptorStateMachine.runTo (/ApplicationPath/node_modules/aws-sdk/lib/state_machine.js:14:12)
at /ApplicationPath/node_modules/aws-sdk/lib/state_machine.js:26:10
at Request. (/ApplicationPath/node_modules/aws-sdk/lib/request.js:38:9)
at Request. (/ApplicationPath/node_modules/aws-sdk/lib/request.js:685:12)
at Request.callListeners (/ApplicationPath/node_modules/aws-sdk/lib/sequential_executor.js:116:18)
at Request.emit (/ApplicationPath/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
at Request.emit (/ApplicationPath/node_modules/aws-sdk/lib/request.js:683:14)
at Request.transition (/ApplicationPath/node_modules/aws-sdk/lib/request.js:22:10)
at AcceptorStateMachine.runTo (/ApplicationPath/node_modules/aws-sdk/lib/state_machine.js:14:12)
at /ApplicationPath/node_modules/aws-sdk/lib/state_machine.js:26:10
at Request. (/ApplicationPath/node_modules/aws-sdk/lib/request.js:38:9)
at Request. (/ApplicationPath/node_modules/aws-sdk/lib/request.js:685:12)
at Request.callListeners (/ApplicationPath/node_modules/aws-sdk/lib/sequential_executor.js:116:18)
at callNextListener (/ApplicationPath/node_modules/aws-sdk/lib/sequential_executor.js:96:12)
at IncomingMessage.onEnd (/ApplicationPath/node_modules/aws-sdk/lib/event_listeners.js:307:13)
at IncomingMessage.emit (events.js:214:15)
at IncomingMessage.EventEmitter.emit (domain.js:476:20) {
message: 'The specified launch template, with template ID lt-03969d13638b5XXXX, does not exist.',
code: 'InvalidLaunchTemplateId.NotFound',
time: 2020-01-22T15:29:18.641Z,
requestId: '16082702-49c0-4451-a3b7-570b930b5238',
statusCode: 400,
retryable: false,
retryDelay: 47.92654090836894
}
The IAM access includes both:
AmazonEC2FullAccess
AmazonEC2FullAccess
(The JSON are super long but I am happy to post those in here if needed)
My thought is that there is some permissioning error for the IAM but I can't determine what that might be. Thank you for the help and please let me know if there is any other clarity I can provide.
When you can see that a given AWS resource exists in the AWS console, but it is not returned by the awscli or SDK calls, (or vice-versa) then one of the following is likely the cause:
you have queried the wrong region
you have queried the wrong AWS account (your effective credentials are for a 2nd, different account)
you have mis-typed the resource name/id
your browser has cached results that no longer exist (refresh your browser)

Can't seem to send email with jhipster application

I'm trying to make a simple form that when submited sends and email to a fixed email.
I'm using spring and i've searched on how to configure the application.yml and i'm using the mailsend method that seems to have been generated with my jhipster application.
I've built my FE service to connect to the back end :
sendForm(): Observable<any>{
return this.http.post(SERVER_API_URL + 'api/sendForm', "");
}
i've built the onsubmit method to make the subscribe to the method above:
onSubmit() {
this.auth.sendForm().subscribe( data => {
console.log(data);
})
}
i've hard coded the mail resource just to mock an email to make sure its working:
#PostMapping("/sendForm")
public void sendForm() {
this.mailService.sendEmail("mymail#gmail.com","Header","texto",false,true);
}
the sendMail method that im sending the information for the mail submition is autogenerated and I believe it should be working
#Async
public void sendEmail(String to, String subject, String content, boolean isMultipart, boolean isHtml) {
log.debug("Send email[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}",
isMultipart, isHtml, to, subject, content);
// Prepare message using a Spring helper
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
try {
MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, StandardCharsets.UTF_8.name());
message.setTo(to);
message.setFrom(jHipsterProperties.getMail().getFrom());
message.setSubject(subject);
message.setText(content, isHtml);
javaMailSender.send(mimeMessage);
log.debug("Sent email to User '{}'", to);
} catch (Exception e) {
if (log.isDebugEnabled()) {
log.warn("Email could not be sent to user '{}'", to, e);
} else {
log.warn("Email could not be sent to user '{}': {}", to, e.getMessage());
}
}
}
and heres my application-dev.yml (i'm still on dev)
spring:
profiles:
active: dev
mail:
host: smtp.gmail.com
port: 587
username: gmailuserid#gmail.com #Replace this field with your Gmail username.
password: ************ #Replace this field with your Gmail password.
protocol: smtp
tls: true
properties.mail.smtp:
auth: true
starttls.enable: true
ssl.trust: smtp.gmail.com
the errors im getting goes as follows:
org.springframework.mail.MailSendException: Mail server connection failed; nested exception is com.sun.mail.util.MailConnectException: Couldn't connect to host, port: localh
ost, 25; timeout -1;
nested exception is:
java.net.ConnectException: Connection refused: connect. Failed messages: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: localhost, 25; timeo
ut -1;
All I expect is a mail with the mock i've used and I cant seem to be able to put this working.
I hope i've not made the post to long and that everything is well explained.
Thank you in advance for anyone willing to help
Apparently somewhy the properties-prod.yml wasnt being loaded to the server. I had to create a config file with all the configurations for it to work

ADAL - AcquireTokenHandlerBase.cs: System.ArgumentNullException: String reference not set to an instance of a String

I used ADAL with ADFS for authenticating web api calls within Xamarin and is experiencing an issue when repeating the authentication process, it appears to be having issue with getting token from the in-memory cache.
Interestingly, I have another demo app which does the same thing and doesn't have the same issue...
The code used is as below, if anyone can shield some lights on how to debug it further it will be much appreciated.
try
{
AuthenticationContext ac = new AuthenticationContext(authority, false);
try
{
ar = ac.AcquireTokenSilentAsync(resourceURI, clientID).Result;
}
catch (AggregateException exc)
{
//do nothing?
}
if (ar == null)
{
ar = await ac.AcquireTokenAsync(resourceURI, clientID, new Uri(clientReturnURI), parent);
}
**catch (Exception ex)** //always been hit
{
2016-08-14 22:54:46.075 TimeSheetiOS[70494:1224472] 8/15/2016 5:54:46
AM: c7b85581-cef2-492c-86ee-5686a5d4de67 - TokenCache.cs: Looking up
cache for a token... 2016-08-14 22:54:46.076
TimeSheetiOS[70494:1224472] 8/15/2016 5:54:46 AM:
c7b85581-cef2-492c-86ee-5686a5d4de67 - TokenCache.cs: An item matching
the requested resource was found in the cache 2016-08-14 22:54:46.076
TimeSheetiOS[70494:1224472] 8/15/2016 5:54:46 AM:
c7b85581-cef2-492c-86ee-5686a5d4de67 - TokenCache.cs: 29.0067555833333
minutes left until token in cache expires 2016-08-14 22:54:46.077
TimeSheetiOS[70494:1224472] 8/15/2016 5:54:46 AM:
c7b85581-cef2-492c-86ee-5686a5d4de67 - TokenCache.cs: A matching item
(access token or refresh token or both) was found in the cache
2016-08-14 22:54:46.082 TimeSheetiOS[70494:1224472] 8/15/2016 5:54:46
AM: c7b85581-cef2-492c-86ee-5686a5d4de67 - AcquireTokenHandlerBase.cs:
System.ArgumentNullException: String reference not set to an instance
of a String. Parameter name: s at System.Text.Encoding.GetBytes
(System.String s) [0x00006] in
/Users/builder/data/lanes/3539/f37444ae/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/text/encoding.cs:1083
at
Microsoft.IdentityModel.Clients.ActiveDirectory.CryptographyHelper.CreateSha256Hash
(System.String input) [0x0000c] in :0 at
Microsoft.IdentityModel.Clients.ActiveDirectory.AcquireTokenHandlerBase.LogReturnedToken
(Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationResult
result) [0x00067] in :0 at
Microsoft.IdentityModel.Clients.ActiveDirectory.AcquireTokenHandlerBase.PostRunAsync
(Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationResult
result) [0x

How do I configure ServiceStack.net to authenticate using the OAuthProvider against Google

I'd like to configure ServiceStack.net to authenticate using the OAuthProvider against Google. Here is my current configuration:
Plugins.Add(new AuthFeature(() => new AuthUserSession(),
new IAuthProvider[] {
new OAuthProvider(appSettings,
"https://accounts.google.com/o/oauth2/auth",
"google",
"Google Client ID",
"Google Client secret")
}));
However, I get the following error:
response Status
error Code ArgumentNullException
message String reference not set to an instance of a String. Parameter name: s
stack Trace
[Auth: 8/19/2013 7:48:47 PM]: [REQUEST: {provider:google}] System.ArgumentNullException: String reference not set to an instance of a String. Parameter name: s at System.Text.Encoding.GetBytes(String s) at ServiceStack.ServiceInterface.Auth.OAuthUtils.PercentEncode(String s) at ServiceStack.ServiceInterface.Auth.OAuthAuthorizer.<>c__DisplayClass3.<MakeSignature>b__1(String k) at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext() at System.Linq.Buffer`1..ctor(IEnumerable`1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source) at ServiceStack.ServiceInterface.Auth.OAuthAuthorizer.MakeSignature(String method, String base_uri, Dictionary`2 headers) at ServiceStack.ServiceInterface.Auth.OAuthAuthorizer.AcquireRequestToken() at ServiceStack.ServiceInterface.Auth.OAuthProvider.Authenticate(IServiceBase authService, IAuthSession session, Auth request) at ServiceStack.ServiceInterface.Auth.AuthService.Authenticate(Auth request, String provider, IAuthSession session, IAuthProvider oAuthConfig) at ServiceStack.ServiceInterface.Auth.AuthService.Post(Auth request) at lambda_method(Closure , Object , Object ) at ServiceStack.ServiceHost.ServiceRunner`1.Execute(IRequestContext requestContext, Object instance, TRequest request)
According to the network trace, nothing ever hits Google.
Thanks!
I also had this problem. My solution was to double check the Web.Config in the root of the service. I didn't have the ServiceStack OAuth Config setup correctly there.
Use the keys:
<add key="oauth.GoogleOpenId.RedirectUrl" value="http://bootstrapapi.apphb.com/friends"/>
<add key="oauth.GoogleOpenId.CallbackUrl" value="http://bootstrapapi.apphb.com/api/auth/GoogleOpenId"/>
and the Google IAuthProvider
new GoogleOpenIdOAuthProvider(appSettings), //Sign-in with Google OpenId

How to validate credentials in EWS Java API

I am using EWSJavaAPI 1.1.5. I am trying to login with invalid credentials, but I don't get any exceptions.
Please advise how to detect and handle invalid login.
Here is my code:
String host = "myhost";
ExchangeService service = null;
try {
service = new ExchangeService();
ExchangeCredentials credentials = new WebCredentials("wrongemail",
"wrongpass");
service.setCredentials(credentials);
service.setUrl(new java.net.URI("https://" + host
+ "/EWS/Exchange.asmx"));
} catch (Exception e) {
e.printStackTrace();
}
Found it, i had to bind the service to a folder:
Folder.bind(service, WellKnownFolderName.Inbox);
and if the credentials are wrong, HttpErrorException is thrown.

Resources