How to get userinfo with Microsoft OAuth after successfully authenticated - java

My applications should login with Microsoft account (OAuth Provider). I got stuck to get user info after successfully authenticated by using following URL
https://login.live.com/oauth20_authorize.srf?client_id=CLIENT_ID&scope=SCOPES&response_type=code&redirect_uri=REDIRECT_URL
Can any one please help me to get user-info? Is there any library that I need to include for that ?
I'm getting authenticated code but I don't know how use ? I'm working with JAVA

The userinfo endpoint is https://apis.live.net/v5.0/me. Before you call it you need to exchange the code for a token.

For anyone stumbling here.
OpenID discovery URL: https://login.live.com/.well-known/openid-configuration
Microsoft doesn't provide userinfo_endpoint in the service configuration json
UserInfo URL : https://graph.microsoft.com/v1.0/me
Make a GET request to this url with header containing access_token that you got after exchanging auth_code
Key: Authorization
Value: Bearer <access_token>

Related

Not able to get an access token for my okta api service via postman

I'm writing a spring boot backend in java which endpoints are secured by okta.
The application uses the okta api service app integration since only the frontend and never a user is retreiving data from it.
To get a valid access token from the okta api I followed these steps: https://developer.okta.com/docs/guides/implement-grant-type/clientcreds/main/#request-for-token
Sadly all my attempts result in an error.
My postman configuration:
Okta api endpoint:
https://dev-61814681.okta.com/oauth2/default/v1/token
Authentication method:
Basic auth with client id as username and client secret as password
Headers:
accept = application/json
cache-control = no-cache
content-type = application/x-www-form-urlencoded
Body:
grant-type = client_credentials
scope = MyDefault
The response:
400 bad request
It would be nice if someone could push me in the right direction with this one.
It should be grant-type instead of what you wrote (grand-type).
Also, make sure you have defined the "MyDefault" scope in your Okta API app and that it has the necessary permissions for your client to access the endpoints it requires.
Hopefully the typo fixes the issue in this case.
I was able to solve my problem by doing the following:
I took the cURL pictured at https://developer.okta.com/docs/guides/implement-grant-type/clientcreds/main/#request-for-token
After that I inserted my Okta domain, added my authorization (client id and client secret written in the same line seperated by ':' and encoded as base64) and updated the scope from customScope to my own custom scope.
I imported all of that into postman by pressing the import button and inserting the raw text.
Now everithing works fine.

How do we authenticate using IDAnywhere Authentication?

What is IDAnywhere authentication? How can we use this authentication in Java to consume an API through its Url. The same url I can access now in browser with an username and password.
Example - www.abc.com/products/id - gives me a json data as a response in the browser.
I want to get this done using and Id Anywhere auth. Please help.
Can anyone share any open resource to understand IDAnywhere authentication in detail.
Thanks in Advance!

How to auth my app with Google LogIn?

I have googled some info but still not undersant exactly how to auth my app with my server side.
I have Google LogIn button, as far as i understand when i click it, i sent request token, then i get back acsess token and can use it to get info from Google API,
but issue is what i should to do to auth the current user with my DB? It is ok that i get a acsess from google to use API, but what about my DB, what i should to do next, how i can concatenate it google logIn and my DB?
Could anybody help me to understand consept of auth and registration user in my DB with Google LogIn button?
Well the basic concept is the following:
Do the Google Login with the option to request an IdToken
Send the IdToken to your server
Check if the IdToken is valid by using one of the Google API Client libraries (here is one for Python)
After the token is verified you'll receive a payload which includes the userId - you can use this userId to identify the user in your backend.
Following a picture of the whole procedure described above:
See the corresponding Blog-Post as well.
This might help with your own oauth2 server
http://bshaffer.github.io/oauth2-server-php-docs/cookbook/

how to implement the instagram login Oauth using javascript and java

I'm new to Oauth and to instagram.I got register for the application and got client id, client secret, redirect url.I don't have any idea how to implement it.Can anyone help me out.
Seems like its not possible to authenticate Instagram Login.There are not still providing any API to authenticate an account with username and password credentials.You can authenticate your account by this request
https://api.instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=code
You will get ClientID by
Register

authorized with google using scribe not getting how to fetch google contacts

I want to fetch contacts from gmail. for this I am using Sribe using GoogleExample.java
Which is working properly and giving me token.
For authorization it is giving me link like
https://www.google.com/accounts/OAuthAuthorizeToken?oauth_token=**
I am doing connection process successfully with google,
1) I want to fetch users contact from his account I am not getting it how to do it. Please provide any example
2) for authorization i have to manually copy link i dont want to do it manually.
Using struts2 for developing this project.
You do not need to do authorization manually,in scribe this has been done for demo purpose and you have way to do this.
follow below mention steps
Create a Controller which create a request to Google API, you need to pass api_key,secret and can pass redirect_url with other information.
Redirect user to Google and let him/her authorize your application
redirect URL tell any OAuth/OpenID provider where to redirect user back once he/she authorize/reject your application
on redirection back, Google will provide you a authorization token.you can than connect to the Google API to fetch user contacts
this is a demo code how you can fetch data from Google once user redirect back to your site
Verifier verifier = new Verifier(oauth_verifier);
Token accessToken = oAuthGetAccessToken.getAccessToken((Token) session.get(OAuthConstants.REQUEST_TOKEN), verifier, service);
service.signRequest(accessToken, request);
Response response = request.send();
What actually is happening, we created a verifier with the help of verifier token send by Google when user redirected back,we got access_token from the Google internally which work as a key to access user data and finally we sent request to Google API to fetch data.
Please be sure to set the scope in your initial request which tell service provider what all data you want to access from the user profile.

Categories

Resources