url method
Generates the authentication URL used for Reddit user verification in a browser.
scopes
is the list of all scopes that can be requested (see
https://www.reddit.com/api/v1/scopes for a list of valid scopes). state
should be a unique String for the current Authenticator instance.
The value of state
will be returned via the redirect Uri and should be
verified against the original value of state
to ensure the app access
response corresponds to the correct request. duration
indicates whether
or not a permanent token is needed for the client, and can take the value
of either 'permanent' (default) or 'temporary'. If compactLogin
is true,
then the Uri will link to a mobile-friendly Reddit authentication screen.
Implementation
@override
Uri url(List<String> scopes, String state,
{String duration = 'permanent', bool compactLogin = false}) {
// TODO(bkonyi) do we want to add the [implicit] flag to the argument list?
var redditAuthUri =
_grant.getAuthorizationUrl(_redirect, scopes: scopes, state: state);
// getAuthorizationUrl returns a Uri which is missing the duration field, so
// we need to add it here.
final queryParameters =
Map<String, dynamic>.from(redditAuthUri.queryParameters);
queryParameters[_kDurationKey] = duration;
redditAuthUri = redditAuthUri.replace(queryParameters: queryParameters);
if (compactLogin) {
var path = redditAuthUri.path;
path = path.substring(0, path.length) + r'.compact';
redditAuthUri = redditAuthUri.replace(path: path);
}
return redditAuthUri;
}