Comments (5)
hi @mayah
you can still set the response_type
even with the current implementation:
let mut authorize_url = config.authorize_url(String::new());
authorize_url.query_pairs_mut().append_pair("response_type", "code");
this should happen somewhere before you call config.exchange_code(code)
.
my issue #8 is about improving the interface, but after #7 I got the Google flow working.
from oauth2-rs.
here's the entire code (in this case for Google Calendar):
let mut config = Oauth2Config::new(
"YOUR_CLIENT_ID",
"YOUR_CLIENT_SECRET",
"https://accounts.google.com/o/oauth2/v2/auth",
"https://www.googleapis.com/oauth2/v3/token"
);
// Point to your redirect URL
config.redirect_url = "http://localhost:8080".to_string();
config.scopes = Vec::new();
config.scopes.push("https://www.googleapis.com/auth/calendar".to_string());
let mut authorize_url = config.authorize_url(String::new());
authorize_url.query_pairs_mut().append_pair("response_type", "code");
let mut code = String::new();
// This is my own-the-fly redirect URL server: Ignore this part if you've got this handled somewhere else
let listener = TcpListener::bind("127.0.0.1:8080").unwrap();
for stream in listener.incoming() {
match stream {
Ok(stream) => {
let mut reader = BufReader::new(stream);
let mut request_line = String::new();
reader.read_line(&mut request_line).unwrap();
let redirect_url = request_line.split_whitespace().nth(1).unwrap();
let url = Url::parse(&("http://localhost".to_string() + redirect_url)).unwrap();
let code_pair = url.query_pairs().find(|pair| {
let &(ref key, _) = pair;
key == "code"
}).unwrap();
let (_, value) = code_pair;
code = value.into_owned();
break;
}
Err(e) => {}
}
};
let token = config.exchange_code(code).unwrap();
from oauth2-rs.
yeah, I'm ok with adding query params after taking authorize_url, however, I don't think it's intuitive. If it's ok, then it might be also ok if we construct authorize_url without this kind of library, right?
Anyway, it looks you're working on enhancing the api interface, I'll wait for your work. (or, I'm ok to make a PR to add an interface.)
from oauth2-rs.
@mayah I've closed that monster ticket and just released 1.0.0 => have a look if it's still of interest. the documentation is available here.
from oauth2-rs.
Hi, thanks for the info! I'll check it.
from oauth2-rs.
Related Issues (20)
- Support OAuth2 with JSON Web Token HOT 1
- Add User-Agent customization HOT 4
- Google example works but fails for async with Yew/Actix-Web HOT 2
- Compounding the sleep intervals if there is an error in the http_client HOT 3
- Github Device Code Flow does not work HOT 1
- microsoft_devicecode flow broken HOT 9
- How do I track state-pkce_verifier pairs for each authorization flow? HOT 2
- refresh_token is None using the tumblr api HOT 1
- Facebook scopes are None HOT 4
- Error: Failed to parse server response. On attempt to exchange token HOT 3
- serde compilation error HOT 3
- Should Authorization Code Grant with PKCE require client secret? HOT 4
- Dealing with apis which don't include token_type in response HOT 2
- example related to AWS cognito? HOT 1
- Consider using `http::{Request, Response}` for easier conversion HOT 9
- Upgrade to http 1.0 HOT 17
- Google Url does not contain code HOT 1
- Does this crate support getting scope data like (profile) ? HOT 2
- Code review of FusionAuth OAuth2 Rust guide please? HOT 1
- Quesion: Client Credentials - am I doing it right? HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from oauth2-rs.