How to track URL in flutter with website platform - flutter

I want to do oAuth2 verification in my website login page and after that I want to get token from url with same page but issue is i can`t able to get URL.
below URL is OAuth2 url using this url I am doing authentication steps with website using flutter.
1st this website will open in browser after that login page will open and after login i will get access_token. But i facing difficulties how i can get access_code with html.window.location function.
I have tried with this code
WidgetsBinding.instance!.addPostFrameCallback((_) {
html.window.location.assign(
'https://example/connect/authorize?response_type=token&client_id=$clientId&redirect_uri=https://example.app/silentRenew&scope=getinfo');
});
Anyone have better solution than please give suggestion.

Pinal! I did an oAuth2 flux recently consuming Gitlab API. I suggest you to use
the oauth2 plugin: oauth2. You just need to have the authorization endpoint, access token endpoint and the redirect url.
After this, you just need to call 3 methods.
Getting your AuthorizationCodeGrant.
var grant = oauth2.AuthorizationCodeGrant(identifier, authorizationEndpoint, tokenEndpoint,secret: secret)
Get Authorization Url.
var authorizationUrl = grant.getAuthorizationUrl(redirectUrl);
Get the returned Code.
await grant.handleAuthorizationResponse(responseUrl.queryParameters);
The method return your code automatically.
In my case, I used a webview instead opening the browser to listen the redirected url's. WebView
You just have to pass the authorizationUrl as the initial page flag inside webview, and listen to the url's with onPageStarted flag. So what you wanna do is: when the redirectUrl ,which gives you the code to authorize your access token, is accessed you call the method 3, only in this moment. I hope this help you, let me know if you struggle with something.

Related

Keycloak - direct user link registration

I have set up a web application with Keycloak in my local machine. Since Im using Keycloak as SSO implementation, I want in my web app that whenever SIGNUP button is click, user is directed into the registration page, and not going through the LOGIN page.
This is the example URL directed to the registration form, however, it contains a tab_id that is generated randomly like a session id.
https://site.test/auth/realms/custom/login-actions/authenticate?client_id=test&tab_id=qIdW92Bvwmk
I read about this link
Yes, as long as you use the "registrations" instead of "auth" in the
end of login ( AuthorizationEndpoint ) URL
But my endpoint in https://site.test/auth/realms/custom/.well-known/openid-configuration cannot be modified.
You can change the button link to this format -
http://<domain.com>/auth/realms/<realm-name>/protocol/openid-connect/registrations?client_id=<client_id>&response_type=code&scope=openid email&redirect_uri=http://<domain.com>/<redirect-path>&kc_locale=<two-digit-lang-code>
The registration page is exposed via an openid-connect endpoint, accessible in the same way as the standard auth screen. To construct the correct URL you can simply replace openid-connect/auth in the URL with openid-connect/registrations from the .well-known auth endpoint.
authEndpoint.replace("openid-connect/auth","openid-connect/registrations");
Using this endpoint the user will be directed to the registration screen instead of the login screen.
It is not documented or exposed via .well-known/openid-configuration, but you can see it in the source code:
public static UriBuilder registrationsUrl(UriBuilder baseUriBuilder) {
UriBuilder uriBuilder = tokenServiceBaseUrl(baseUriBuilder);
return uriBuilder.path(OIDCLoginProtocolService.class, "registrations");
}
For Keycloak 17 this worked for me:
http://<mykeycloakdomain.com>/realms//protocol/openid-connect/registrations?client_id=<myclient_id>&response_type=code&scope=openid+email&redirect_uri=https%3A%2F%2Fmywebsiteurl.com&kc_locale=

How to simply use facebook login for my app without using the SDKs?

Is there a simple flow (hello world) for a user to login using facebook?
Found documentation on Manually Build a Login Flow, but is too full of text and details that I don't see the main flow.
Based on Manually Build a Login Flow (showing only the minimal data needed to make it work):
Create a facebook app.
Simulate the user clicking on the following authentication URL to allow the app to access the user's data: https://www.facebook.com/v2.8/dialog/oauth?client_id=<app id>&redirect_uri=http://localhost/
Click ok/accept/whatever to authorize access.
You get redirected by facebook to a URL of the following: http://localhost/?code=<code>
Take the code and invoke the following: curl 'https://graph.facebook.com/v2.8/oauth/access_token?client_id=<app id>&redirect_uri=http://localhost&client_secret=<app secret>&code=<code>'
You get a result like the following: {"access_token":"<access token>","token_type":"bearer","expires_in":5183924}
You can then use the access token to call API related to the user that gave the permissions to your app. Example: curl 'https://graph.facebook.com/v2.8/me?access_token=<access token>'
Example response: {"name":"Alik Elzin","id":"<app related user id>"}
* Remember to add http://localhost/ to the app's Valid OAuth redirect URIs - under app settings.
Have you checked out this documentation from Facebook? It's pretty short to read through: https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow

How to add Dreamfactory OAuth facebook login in Ionic?

I am trying to implement Dreamfactory OAuth in Ionic app.
I am following this resource for implementation:
http://wiki.dreamfactory.com/DreamFactory/Tutorials/Using_OAuth
This is the call I am making:
$http.post('/api/v2/user/session?service=facebook').then(function (result) {
console.log("result: "+ JSON.stringify(result));
});
The log above shows me json data as it itself redirects to the facebook url returned by the call and it just returns HTML for that facebook page.
Is there a different approach I should be using in hybrid/Ionic apps for DF OAuth login?
Make that an Ajax call (or simply set request header [X-Requested-With: XMLHttpRequest]). This will return the actual URL that is needed, not the redirected response in html. Let me know if you have any questions.

Connect to SoundCloud API with Facebook account

Using the SoundCloud API to show the logging in screen with the following URL:
https://soundcloud.com/connect?client_id=[my_client_id]&redirect_uri=[my_redirect_url]&display=popup&response_type=code&scope=non-expiring
When clicking on the Sign in with Facebook button, I get the Facebook screen and enter the details.
When returning, I get the following URL:
https://soundcloud.com/connect/via/facebook/returning?code=[returned_code]&state=[returned_state]
Using the returned code as from the URL above to get the token, via url (https://api.soundcloud.com/oauth2/token) with payload
{
client_id=[my_client_id],
client_secret=[my_client_secret],
grant_type=authorization_code,
redirect_uri=[my_redirect_url],
code=[code_as_returned_above]
}
I get a 401 (Unauthorized) error.
Am I doing something wrong using facebook for signin in?
Note, this method works perfectly when using SoundCloud credentials in the sign in page.
No response from SoundCloud to provide a solution.

Facebook cannot redirect the next parameter

When I authenticate the user, after authentication it does not redirect the next parameter. Instead it redirect the user to the "Canvas Callback URL". If I dont give the convas callback url. then it gives the error
An error occurred with experiement. Please try again later.
API Error Code: 100
API Error Description: Invalid parameter
Error Message: next is not owned by the application.
on the other hand if the user cannot allow my app then it redirect the next parameter.
My url for authentication is:
https://login.facebook.com/login.php?api_key=**KEY**&v=1.0&popup=1&next=**NEXT**&
next_cancel=**NEXT_CANCEL**&skipcookie=1
I try to this on localhost.
in any one have idea about this?
Try using this url instead to get permissions:
$facebook->redirect('https://graph.facebook.com/oauth/authorize?
client_id=[YOUR APP ID]&
redirect_uri=[YOUR APP URL]&
scope=publish_stream, offline_access');
Replace [YOUR APP ID] with application id that you can see from application settings where you created the site in Facebook Developers section. Also replace the [YOUR APP URL] with your app url.
And $facebook variables is the one you get by initiating the facebook client that is:
$facebook = new Facebook($appapikey, $appsecret);
Yes it always redirects to canvas url instead of app url. You just need to create your own server side redirect that would redirect user back to app url.
You can separate regular app calls from the one after authorization that requires manual redirect by looking at request parameters. After authorization you would get some unique params like auth_token that are not present in a regular request. If those params are present - it means that it is authorization redirect and you need to send user back to app url.